What I have:
@Entity public class MyEntity { @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, orphanRemoval = true) @JoinColumn(name = "myentiy_id") private List<Address> addreses; @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, orphanRemoval = true) @JoinColumn(name = "myentiy_id") private List<Person> persons;
What a problem:
The problem is that I cannot get a lazy collection after closing the session. But I also canβt close the session in the continue method.
Which solution (rude decision):
a) Before closing the session, make sleep mode pull lazy collections
entity.getAddresses().size(); entity.getPersons().size();
....
b) Perhaps a more attractive way is to use the @Fetch(FetchMode.SUBSELECT) annotation @Fetch(FetchMode.SUBSELECT)
Question:
What is the best practice / general way / more flexible way to do this? The tool converts my object to JSON.
java hibernate lazy-loading
VB_ Nov 12 '13 at 11:59 a.m.
source share