Here are mappings:
Code:
public class TreeIdentity {
...........
@ManyToOne()
@JoinColumn(name="parent_id")
public TreeIdentity getParent() {
return parent;
}
...........
@OneToMany(fetch=FetchType.LAZY, cascade=CascadeType.ALL)
@JoinColumn(name="parent_id")
@IndexColumn(name="child_position")
public List<TreeIdentity> getChildren() {
return children;
}
...........
@OneToOne(
mappedBy="revisionObject"
cascade={CascadeType.ALL}
)
public Revision getLastRevision() {
return lastRevision;
}
}
public class Revision {
..........
@OneToOne(cascade = {CascadeType.ALL})
@JoinColumn(name="identity_revision_id")
public TreeIdentity getRevisionObject() {
return revisionObject;
}
..........
}
This mapping creates foreign key "identity_revision_id" in Revision table pointing to TreeIdentity. When I call getChildren() on TreeIdentity, the getLastRevision() is null.
I changed the inverse side (e.g. I put the join column in TreeIdentity table and put "mappedBy" in the Revision and it worked like a charm.
It is bugging me what was the real cause of the problem