[jboss-user] [JBoss Seam] - LazyLoading question when accessing to attributes from class

ElNino do-not-reply at jboss.com
Thu Dec 6 10:59:39 EST 2007


Hello,

I have set some attributes with LazyLoading property, it's working great. But I have question.

Take this example


  | @OneToMany(mappedBy = "content", cascade = { CascadeType.PERSIST,
  | 			CascadeType.MERGE, CascadeType.PERSIST, CascadeType.REFRESH }, fetch=FetchType.LAZY)
  | private List<Content> contents;
  | 
  | ....
  | with the setter and getter.
  | ....
  | 
  | 

If I call getContents() method, the lazy loading is working perfectly and hibernates doing his job.

Now if I have a method that make a search in contents list... I will have


  | 
  | public void doStuffInContents() {
  | 
  | // Doing stuff on contents attributes...
  | 
  | }
  | 
  | 

Of course, the contents attributes is null...

The solution can be using getContents() method instead contents attributes directly.

Anothe one could be :

  | if (contents == null)
  | contents = getContents();
  | 
in each method using the attributes.

But I don't like these two...

I would like to get your point of view... Thanks !

Regards,

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4110899#4110899

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4110899



More information about the jboss-user mailing list