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 this right?) the new uncommited persistent
Entity will be loaded into that List when the list is first accessed.
So I do not need to explicitly call List.add(newEntity) which would
force the List to be loaded.
But if do access the List for some reason and then create and persist a
second Entity the List will be out of date unless I explicitly add the
new Entity to the list.
Hope that makes sense - Perhaps what I am looking for is a way to detect
if the List has already been fetched before I explicitly call
List.add(newEntity).
Here are my related Entities (not sure if this is correct or not). The
scenario is that I am creating new Members that are members of the List
in Master.
@Entity
public class Master implements java.io.Serializable
{
. . .
@OrderBy
@OneToMany(mappedBy="master", fetch=FetchType.LAZY,
cascade={CascadeType.PERSIST,CascadeType.REMOVE})
private List<Member> members;
public List<Member> getMembers() { return members; }
}
@Entity
public class Member implements java.io.Serializable
{
@ManyToOne (optional=false, fetch=FetchType.LAZY,
cascade=CascadeType.PERSIST)
private Master master;
}