I have a many to one relationship setup where the primary column of the parent does not participate in the relationship. I am using the @JoinColumn annotation and seem to have it working now, it took me about a week to figure out what is going on. This is is what I have discovered and I want to know if it is proper behavior or if it is a bug. The following are reference part of the classes I used, simple parent and child.
Class Parent:
@OneToMany(mappedBy="myParent")
private List<Child> childs;
public List<Child> getChilds() {
return childs;
}
public void setChilds(List<Child> childs) {
this.childs = childs;
}
Class Child:
@ManyToOne
@JoinColumn(name="placer_id", referencedColumnName="placer_id")
private Parent myParent;
public Parent getParent() {
return myParent;
}
protected void setParent(Parent parent) {
this.myParent = parent;
}
The problem is that in the child if I have the setParent method public it an exception that results in the following.
Caused by: javax.xml.bind.MarshalException
- with linked exception:
[com.sun.istack.SAXException2: A cycle is detected in the object graph. This will cause infinitely deep XML
If the method is protected or non-existent it runs with no problems. I can see why you possibly don't want the parent changed from the child but I have not seen any documentation on this not being allowed, though I have not completed reading the spec yet. I have been reading a hibernate 3 book, though this is being written with toplink, which shows a public modifier on the parent object of a ManyToOne relationship.
The bad thing is that I was looking everywhere else for the problem and simply told NB to generate standard getters and setters for me, which seems to be my downfall.
Is this proper behavior or a bug?
---
Dru Devore