-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: JPA - Lazy Initialisation
PostPosted: Fri Jul 24, 2009 6:36 am 
Newbie

Joined: Fri Jul 24, 2009 6:25 am
Posts: 3
Hi All,

I hope this isn't a repeat question. I have looked, and google'd, this question for sometime. I am just looking for guidance on the best approach.

The Problem:
I have an entity which has 2 Collections which represent a Many-to-Many relationship with 2 other entities. Now I have them both set to be lazily fetched, as I don't require that information all the time.

Question:
However in the instances I do want that information, what is the best approach to get them loaded. ?

From Research:
I have seen various ways of getting these collections loaded, one being the "EntityManager in View" design pattern, but with my beliefs leaning toward the pure computer science side, it just doesn't feel right. Another is to have a facade that calls on those collections, forcing Hibernate to populate them.

E.g.
Code:
@Transactional
public MyEntity getMyEntity(Long id) {

   // Call to underlying service method
   MyEntity rtn = service.getMyEntity(id);

   // Force Hibernate to load the collections
   rtn.getCollection1().size();
   rtn.getCollection2().size();

   return rtn;
}


Again, I don't feel comfortable with this. Maybe I am being overly pure and missing something glaringly obvious, this may not even be a problem at all and I have over-complicated things.

Would be great if someone else offered their insight into this problem.

Kind Regards to All

Cookie


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.