Best practice for LAZY OneToMany

2009-03-28 Thread Paul Copeland
Here is a naive question about a OneToMany relationship. This is probably a basic question. I have a lazily fetched List. It might be large and I don't want to load it until it is accessed. In a transaction - If I create and persist a new Entity that is a member of the list, I think (is

Re: Best practice for LAZY OneToMany

2009-03-28 Thread catalina wei
Paul, When you get a Master entity into your persistent context, because members is LAZY field it should not be loaded. Persisting a Member entity should not affect this LAZY field unless you access the list by calling getMembers(). You must set the master field in newly created Member instance

Re: Best practice for LAZY OneToMany

2009-03-28 Thread Paul Copeland
Hi Catalina - All of what you said confirms my understanding. One question I have is will a new Persistent member that has not been flushed in the same transaction be returned by getMembers()? My other question is what happens if I create a Member after calling getMembers()? Will that new

Re: Best practice for LAZY OneToMany

2009-03-28 Thread Paul Copeland
Does this sequence of calls satisfy my requirement? Is there a better way? Member newMember = new Member(master); entityManager.persist(newMember); entityManager.flush(); entityManager.refresh(master); // reloads the list if List has already been lazily loaded Hopefully refresh() does not