hibernate

Should you default to the JPA provider of the application server?

I have a 100% JPA2 compliant application which needs to be portable to many application servers. Being JPA compliant (theoretically) means we can switch JPA providers via configuration (e.g. without changing source code) -- (right???). When running within a servlet container (e.g. Tomcat, Jetty) the application is configured to run w...

Hibernate without primary keys generated by db?

I'm building a data warehouse and want to use InfiniDB as the storage engine. However, it doesn't allow primary keys or foreign key constraints (or any constraints for that matter). Hibernate complains "The database returned no natively generated identity value" when I perform an insert. Each table is relational, and contains a unique ...

Selecting one object from a one-to-many relationship in Hibernate

I have two tables: Job job_id, <other data> Job_Link job_link_id, job_id, start_timestamp, end_timestamp, <other data> There may be multiple records in Job_Link specifying the same job_id with the start_timestamp and end_timestamps to indicate when those records are considered "current", it is guaranteed that start_timestamp and end_...

How to compile hibernate project with maven?

I am novice to maven (as well as to hibernate) but want to learn both. I have downloaded a sample project from hibernate.org and now trying to compile it with maven but getting following error: [INFO] Scanning for projects... Downloading: http://repo1.maven.org/maven2/org/hibernate/hibernate-parent/3.5.2- Final/hibernate-pare...

Setting database-agnostic default column timestamp using Hibernate

I'm working on a java project full of Hibernate (3.3.1) mapping files that have the following sort of declaration for most domain objects. <property name="dateCreated" generated="insert"> <column name="date_created" default="getdate()" /> </property> The problem here is that getdate() is an MSSQL specific function, and when I...

Hibernate search keeps trying to download wstx-asl-3.2.7.pom

Using Maven and Hibernate search I keep get the following info messages in my log: Downloading: http://repo1.maven.org/maven2//woodstox/wstx-asl/3.2.7/wstx-asl-3.2.7.pom ...

Hibernate query for multiple items in a collection

I have a data model that looks something like this: public class Item { private List<ItemAttribute> attributes; // other stuff } public class ItemAttribute { private String name; private String value; } (this obviously simplifies away a lot of the extraneous stuff) What I want to do is create a query to ask for all I...

Need to map classes to different databases at runtime in Hibernate

I have MainDB database and unknown number (at compile time) of UserDB_1, ..., UserDB_N databases. MainDB contains names of those UserDB databases in some table (new UserDB can be created at runtime). All UserDB have exactly the same table names and fields. How to handle such situation in Hibernate? (database structure cannot be change...

Spring configuration of C3P0 with Hibernate?

I have a Spring/JPA application with Hibernate as the JPA provider. I've configured a C3P0 data source in Spring via: <bean id="myJdbcDataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close"> <!-- Connection properties --> <property name="driverClass" value="$DS{database.class}" /> <property name=...

Hibernate EntityManagerFactory EntityManager

Can I create an EntityManager from EntityManagerFactory outside a bean. If so, how would I do it? ...

Deletes not cascading for self-referencing entities

I have the following (simplified) Hibernate entities: @Entity @Table(name = "package") public class Package { protected Content content; @OneToOne(cascade = {javax.persistence.CascadeType.ALL}) @JoinColumn(name = "content_id") @Fetch(value = FetchMode.JOIN) public Content getContent() { return content; }...

hql query formation

Hi I want to construt a hql query like select PLAN_ID from "GPIL_DB"."ROUTE_PLAN" where ASSIGNED_TO in ('prav','sheet') and END_DATE > todays date I am doing in this way but getting an error in setting parameters s=('a','b'); Query q = getSession().createQuery("select planId from RoutePlan where assignedTo in REG "); if(selUs...

Using property file in hibernate mapping

Hi, I have a two nodes environment using the same database. In the database there is a resource table like RESOURCE_ID, CODE, NODE The content of the NODE column can be 1 or 2 depending on which node can use it. As I need to deploy the same ear to the two nodes, I would like to map this table like this: <hibernate-mapping> <cla...

How to get the DiscriminatorValue at run time

We have the following classes @Entity @Inheritance(strategy = InheritanceType.SINGLE_TABLE) // optional annotation as this is default @DiscriminatorColumn(name = "apType", discriminatorType = DiscriminatorType.STRING, length = 255) @DiscriminatorValue("AP") public class ApplicationProcess { } And this @Entity @DiscriminatorValue("AP...

[N]Hibernate: view-like fetching properties of associated class

(Felt quite helpless in formulating an appropriate title...) Is it possible to define a mapping for a class such that some properties are fetched from another table using a join query? In my C# app I display a list of "A" objects, along with some properties of their associated "B" objects and properties of B's associated "C" objects: ...

How to keep an Hibernate's Session open until the page is rendered

I'm having the following problem: I'm using Oracle ADF for the view and controller of my app. With OpenSessionInViewFilter, I intercept the request and open an Hibernate's Session, and it is closed as soon as the bean's method finishes. What I need is to keep the Session opened until the page is rendered, because in my JSP y use the ...

How to escape wildcard characters in "like" clause in HQL?

How can I escape the wildcard characters in a like clause? E.g.: select foo from Foo as foo where foo.bar like '%' || :filter ||'%' query.setParameter("filter", "%"); query.list(); // I'd expect to get the foo's containing the '%' in bar, not all of them! Any ideas? ...

problem with "select new Object ... join ... where"

Hi, I'm having a problem with an HQL query Three classes ClassOne is my BusinessObject public class ClassOne { private int id; private int status; private Set<ClassTwo> classTwos; + other fields/getters/setters/constructor etc } ClassTwo is referenced in a set of ClassOne and is kind of the history of an object of Cl...

How to implement Flex front end with back ends of Java hibernate and JPA?

Hi guys I have a designed a back end solution with Java Hibernate and JPA. Now I want to implement it with Flex front end. How shall I do it? Is it possible without using BladeDS? Just using Servlet or something? Please guide Thanks ...

Automatically Persisting a Complex Java Object

For a project I am working on, I need to persist a number of POJOs to a database. The POJOs class definitions are sometimes highly nested, but they should flatten okay, as the nesting is tree-like and contains no cycles (and the base elements are eventually primitives/Strings). It is preferred that the solution used create one table per ...