I have Persistent class, referring to many collections with LAZY fetch type, like
@Entity
@Table(name = "TABLE")
public class Table implements Serializable {
....
@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
@JoinColumn(name = "LIST1", nullable = true)
private ArrayList list1;
@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
@JoinColumn(name = "LIST2", nullable = true)
private ArrayList list2;
@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
@JoinColumn(name = "LIST1", nullable = true)
private ArrayList list1;
@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
@JoinColumn(name = "LIST2", nullable = true)
private ArrayList list2;
....
}
I have instantiated some objects of type TABLE through Hibernate, added it to a list of Tables, and now want to fetch one of this collections (say list2) for all objects in this list.
for(Table table:tables){
result=table.list2;
....
}
But this way Hibernate will generate sequence of separate SQL queries. Can hibernate fetch list2 for all the objects in collection in one query? (It is important not to create new Table class instances, but modify objects, that are already exists)
From the reference manual: