Hi all,
I am having some problem with lazy loading. Here is an example of my mappings
@Entity public class GrandParent { @Id @GeneratedValue(strategy = GenerationType.AUTO) private Long id;
@OneToMany(mappedBy = "grandParent", cascade = { CascadeType.ALL }) @org.hibernate.annotations.Cascade({ org.hibernate.annotations.CascadeType.DELETE_ORPHAN }) private Set<GrandParentParent> grandParentParents = new HashSet<GrandParentParent>(); }
@Entity public class GrandParentParent { @Id @GeneratedValue(strategy = GenerationType.AUTO) private Long id;
@ManyToOne(fetch = FetchType.LAZY, cascade = { CascadeType.ALL }) @JoinColumn(name = "parent_id") private Parent parent;
@ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "grandParent_id") private GrandParent grandParent; }
@Entity public class Parent extends { @Id @GeneratedValue(strategy = GenerationType.AUTO) private Long id;
@OneToMany(mappedBy = "parent", fetch = FetchType.LAZY, cascade = CascadeType.ALL) private Set<GrandParentParent> grandParentParents = new HashSet<GrandParentParent>(); }
public FamilyVo load(Long idGrandParent ,Long idParent) { FamilyVo vo = new FamilyVo(); GrandParent grandParent = this.loadGrandParent(idGrandParent ); Parent parent = this.loadParent(idParent);
vo.setGrandParent(grandParent); vo.setParent(parent); return vo; }
In the same transaction I want to load an object of class GrandParent but I donĀ“t want to load de collection of GrandParentParent, then I want to load an object of class Parent that is member of collection GrandParentParent but this objet has proxy CGLIB and later in the presentation layer I get LazyInitializationException. I think happen because I load first the object of class GrandParent that has in its collection the object of class Parent, it is in the Session.
Any suggestion???
Thank you in advance
|