Hi, I have an EJB3 application written with JPA and using Hibernate as the JPA provider. I have rich object graph which built from entities each has it's own table. For example I have Process, which has collection of Activity which in turn has collection of Participant which in turn has collection of Elements.
When I select a process I would also like to eagerly select all the other related entities like Activity, Participant and Element. I have set the featch value of the OneToMany annotation to be EARER but yet hibernate issue select statement for each entity.
My database is pretty small (20 MB) but yet selecting two processes, each has about 30 activities each with 2 participants each with 2 elements table about 2-20 seconds. I'm using SQL Server Express as back-end and I've try to select the information manually and it was very fast - I think the problem is in the multiple statements. I've also try to use BatchSize annotation which reduce the number of statements from 460 to 100 but remain equally slow.
How can I make sure hibernate eagerly select the whole entities in fewer statements possible - preferably one statement. I'm ready to build HQL query specifically for this select but I need it to be faster.
Thank you, Ido.
|