hibernate

Setting fetch mode via criteria several levels deep in object graph.

I have a situation where entity A contains a set of entity B. Each entity B contains one entity C. Each entity C has a list of entity D's. I want all A's that meet some criteria but I also want the D's eagerly loaded (mapping file lazily loads them). I have code similar to the following Criteria aCriteria = session.createCriteria(A.clas...

Is it a good practice to let Hibernate create the tables automatically using <property name="hbm2ddl.auto">create</property> ?

I know that adding "hbm2ddl.auto"=create Hibernate will create the tables automatically reading the mapping from the hbm / the annotation. Please let me know that if this is a good practice to follow and why? ...

org.hibernate.exception.SQLGrammarException: could not insert:

Hi Im running example using hibernate with postgresql 8.4, when i try to add it will dispay following error org.hibernate.exception.SQLGrammarException: could not insert: [com.claystone.db.OrWorkgroup] at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67) at org.hibernate.exception.JDBCExceptionHelper.c...

Database view for multiple one to many relationships

Hi, What is the best way to design a view for a Java/Hibernate Application for the following scenario: There is Entity A that has one to many relation with Entity B, Entity C and Entity D. There is a need to show all the relations of Entity A in a single Table in the UI. Does it make sense to create a database view and map that with ...

How to detach all objects from Hibernate session

From time to time I need to clean Hibernate session. How to prevent LazyInitializationException with obects that are attached to this session? I am searching for something like session.detachAllObjects(). and then invoke session.clear() After this I suppose these objects will be retrieved from DB. ...

Hibernate persistence slow on One-To-Many

I have a quite large object tree structure that I persist with Hibernate. This should have been persisted with the root-node first and then the children and so on. However this was not the way that Hibernate did it, it persisted the child first and than updated the reference column in the child when the parent had been persisted. This is...

I am confused of Hibernate?

I learnt JPA for ORM. Now i am asked to use Hibernate as my provider. If i start with Hibernate it is going down in different concept. Please say me How can i relate JPA and hibernate together. JPA reduces my Java code into simple code for persisting Objects. Now what does hibernate help JPA and what does it provide. Anyone plea...

org.hibernate.ejb.HibernatePersistence cannot be cast to javax.persistence.spi.PersistenceProvider

Hello friends, I am developing an application using SPRING 3.0.4, JPA 2, Hibernate 3.5.5. I an trying an existing example given on link http://www.javacodegeeks.com/2010/05/jboss-42x-spring-3-jpa-hibernate.html. only difference is that I am using latest versions of libraries and JBOSS server. Following is list of my /WEB-INF/lib dire...

Is it possible to remove order from Hibernate Criteria?

If I have an @OrderBy("someProperty") annotation on an object and then use a Criteria to add an ORDER BY clause like so: criteria.addOrder(Order.asc("id")); The resulting SQL will do the ordering like this: ORDER BY someProperty, id asc Is it possible to change the order of the two or to remove the someProperty order? I can't r...

HQL Query to check if size of collection is 0 or empty

I try to generate a HQL query that include user with a empty appoinment collections(mapped by OneToMany): SELECT u FROM User u JOIN u.appointments uas WHERE u.status = 1 AND (uas.time.end < :date OR size(uas) = 0) I tries it on several manners (NOT EXIST ELEMENT(), IS NULL) also see: http://stackoverflow.com/questions/1105011/how-to-c...

org.hibernate.MappingException for domain classes in grails

I have a grails project and everything has been running fine. I started adding JAXB XML annotations to my groovy domain classes and all of a sudden I start getting this stack dump. What do I need to do to fix this, and why is it showing up after I started added the XML annotations? 2010-09-21 09:46:43,006 [main] ERROR context.ContextLoa...

How to add a separate Primary Key to a Join Table in Hibernate

Hi there, I have a question about Hibernate ManyToMany mappings. I have two classes A and B and the mapping between them is a ManyToMany mapping resolved by Hibernate: @Entity @Table(name="A") public class A { @Id @GeneratedValue private Long id; @ManyToMany @JoinTable(name="C", joinColumns=@JoinColumn(name="a_id"...

Hibernate vs iBatis

We are building a fairly database centric web application. We initially started off using iBatis. At one point we thought iBatis may not be very useful for the following reasons: 1. Need for the appl. code to determine if we need to insert/update/delete from DB 2. Appl. code will deviate from being object oriented to being database ori...

How to ship database updates?

I have a Java application (generic) that uses a database via hibernate. I ship it via jar to clients. Which is the best way to ship database updates (schema and data) to clients? Consider that clients can have different version of my application, and the update must be automatic, without user support. And if the application is written w...

HIbernate fetch join issuing additional sql statements.

Consider the following Parent class that has two ManyToOne references. @Entity @Table(name = "PARENT") public class Parent { private static final long serialVersionUID = 3730163805206219313L; @Id @SequenceGenerator(name = "SEQ#PARENT", sequenceName = "SEQ#PARENT", allocationSize = 1) @GeneratedValue(strategy = GenerationType.SEQUENCE,...

What Query should i use in Hibernate to fetch POJO?

I learnt Hibernate and used it to reduce my Java code to a vast extent and also able to reduce the time spent for DB's. Now what type of query should i use to finish my operations for getting a DB list to be displayed, to update and delete. My code for deletion is String newToken = "DELETEUSER"; if(!TokenManager.checkRoleToken(newTo...

funtion of getHibernateTemplate().flush()

I am new to Hibernate. Please tell me what is the use of getHibernateTemplate().flush() and how it works. ...

How to create Many-One Mapping in hibernate?

Hi, I want to create Many-One Mapping between two tabels, Expense(ID, NAME, CATEGORY) and Category(ID, NAME). In my class i have created a field 'Category category' and its setters and getters. I did them after seeing some stuff from internet. What are all the changes i have to do in my Category.java class. For now, its looks like, pub...

Hibernate inheritance and HQL

Hello Hibernate daemons, I have inheritance in Hibernate for where Connection is my parent entity, and MobilePhoneConnection is extended entity. I used one table per subclass strategy for inheritance mapping. This is my file: <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3...

Why doesn't my (spring)HibernateTransactionManager work in wicket?

I tried to shorten this to what I think is relevant, I hope it's sufficient and not overwhelming. Please help! I'm converting a small wicket+databinder+hibernate web application to use wicket+spring+hibernate. I have a DAO service class, with a hibernate SessionFactory injected by Spring. I am able to do read-only operations using the s...