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;
}
}