[jboss-user] [Persistence, JBoss/CMP, Hibernate, Database] - lazily initialize collections in their getters

mars1412 do-not-reply at jboss.com
Wed Aug 6 04:41:46 EDT 2008

I am thinking of using lazy initialization of collections in thier getters:
   private java.util.Set<MyEntity> myEntities;
  |    public java.util.Set<MyEntity> getMyEntities() {
  |       if (myEntities == null) {
  |           myEntities = new HashSet<MyEntity>();
  |       }
  |       return myEntities;
  |    }

this would be nice because I would not need the explicit null checks in my buissneslogic.

however I have a bad feeling about this - I'm if this will work in all cases with lazy loading, hibernate proxies and stuff I might not even know about.

What do you think?

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

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

More information about the jboss-user mailing list