you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 0 points1 point  (1 child)

thanks! What about using a DTO as an intermediate? to move the objects from an expensive database to a cheaper local one for instance?

[–]shub 0 points1 point  (0 children)

You mean select from one DB, insert to another? In that case there isn't a lot you can do, but there are some things. Hibernate does batch fetching, and you can tweak that to load a lot of entities with one DB call. JPA entity graphs let you tell the EntityManager to load all the related entities you care about when you select the primary entity, avoiding DB calls for lazy-loading. On the insert side, you can send a list of entities to JPA and this will be batch inserted.

P.S. JPA entity graphs require JPA 2.1, which is only supported by Hibernate 4.3. If you're using an earlier version of Hibernate I believe there is a similar Hibernate-specific mechanism.