-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Lazy Loading not working
PostPosted: Sat Jan 15, 2011 11:49 am 
Newbie

Joined: Fri Jan 11, 2008 3:25 pm
Posts: 7
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.