-->
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 load on Self join entity
PostPosted: Sun Aug 28, 2011 3:45 pm 
Newbie

Joined: Sun Aug 28, 2011 2:57 pm
Posts: 1
Hello guys,

I have an entity that has a many-to-one relationship using a foregin-key self-join into the same table (SearchTag)

So, each SearchTag instance may have 0 or many SeartTags instances (mapped by the FK column named ParentTagId)

The table structure is:
SearchTag - (TagId PK, ParentTagId FK(TagId), Name)

Everything is working in my code, but I want to create this association with the lazy-load behavior (and it isn't working in the code below)

When I retrieve one SearchTag instance (that has a parent) the parentTag property gets loaded always, and I don't want it! I want this property to be loaded only when It hit its getter method...

Please, can someone halp me? Thanks!

Code:
@Entity
@Table(name="SearchTag")
public class SearchTag implements Serializable, CycleRecoverable{

   @Id
   @GeneratedValue(strategy=GenerationType.IDENTITY)
   @Column(name="TagId")
   private long tagId;   
   public long getTagId() {
      return tagId;
   }
   public void setTagId(long tagId) {
      this.tagId = tagId;
   }
   
   @XmlTransient
   @ManyToOne(
         targetEntity=org.ecmlib.core.entity.SearchTag.class,
         cascade={CascadeType.PERSIST, CascadeType.MERGE},
         fetch=FetchType.LAZY
         )
    @JoinColumn(name="ParentTagId")
   private SearchTag parentTag;
   public SearchTag getParentTag() {
      return parentTag;
   }
   public void setParentTag(SearchTag parentTag) {
      this.parentTag = parentTag;
   }
}


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.