We are using Hibernate 4.1.4 with an entity manager implementation and are very pleased with it. When loading a single entity or small sets of entities (10-50 + sub-entities) we get excellent performance and all our joins work great and are bi-directional. Editing/saving/deleting is a breeze!
Loading 2500 Entities & Related Data for ReportingWe are running into problems when we try to load hundreds or thousands of entities along with sub-entities. In one example we have about 2500 base entities along with two one-to-one and three one-to-many joins. This results in 2500 x 5 +1 queries. Takes about 30 seconds to execute with our database (DB2).
We use a dynamic query and the entity manager create query method:
http://docs.jboss.org/hibernate/orm/4.1/javadocs/http://docs.oracle.com/javaee/6/api/jav ... nager.htmlAttempting to coax Hibernate to use JoinsOur observations have been that no matter what we try, we can't seem to get hibernate to execute loads of sub-entities as joins on the primary query. When loading a single entity using the find method and by primary key hibernate uses joins, but when multiple base entities are loaded it does not.
We have tried criteria api with the same result.
Some Success Retrieving Multiple Entities in QueryExample:
select a,b from table1 a left join table2 b
We have had partial success doing the joins manually in our query and retrieving the individual entities via tuples but this bypasses our annotated entity model and is not the preferred method (if we can avoid it).
http://docs.jboss.org/hibernate/orm/4.1 ... -executingThe problem we have encountered with tuples is they are detached from the primary entity (which seems logical as they are not loaded via annotated relationships) and there seems to be no way to re-attach them. After manually adding all the one-to-many records in the list of an entity, when hibernate hits the get method for the list, it still tries to eager/lazy load the list (despite the list already being set).
Attempted Optimization - Preloading of Data SetsAnother optimization technique we attempted was to pre-load sets of data in advance. After loading all the core entities we built a list of the pk's and fired a single query off to load all the one-to-many sets of data. But again when hibernate hits the getter for the list data it again tries to eager/lazy load the list ignoring what is already pre-loaded in the session (need to enable caching perhaps?).
Suggestions/advice?We are going in a number of different directions with little success and are hoping someone might be able to point us down the right path (or point out a new one!)!
I have also posted this question to StackOverflow if anyone would also like to answer it there:
http://stackoverflow.com/questions/11487681/using-hibernate-4-1-jpa-2-0-with-an-entity-manager-what-is-the-optimal-way-to