I have read the parent/child section in the documentation and this *should* be easy, but it just ain't workin. I have a Position object and a PositionSkills object. The Position object can have 0-n skills. Therefore, I have this XDoclet code on my getter:
Code:
/**
* @return a list of skills associated with this position
*
* @hibernate.bag name="skills" table="position_skill" inverse="false"
* cascade="all-delete-orphan"
* @hibernate.collection-key column="position_id"
* @hibernate.collection-one-to-many
* class="us.co.adams.apptracker.persistence.PositionSkill"
*/
public List getSkills() {
return skills;
}
My PositionSkill object merely has a positionId column with the following:
Code:
* @hibernate.property column="position_id"
*/
public Long getPositionId() {
return positionId;
}
If I add an addSkill() method to my Position object, to set the positionId when adding a new skill to the Position, everything works as expected.
Here's where the problem comes into play. The documentation says I should let the PositionSkill class handle it's parent. So I change inverse to "false" on the getSkills() mapping and I add a parent property + getters/setters to the PositionSkill object. Then I map it with the following:
Code:
/**
* Return the position that requires these skills
*
* @return Position - the position that holds these skills
* @hibernate.many-to-one name="position" column="position_id" not-null="true"
*/
public Position getPosition() {
return position;
}
I have to change the getPositionId's mapping to have update="false" and insert="false". I also change the Position.addSkill method to use setParent(this) instead of setParentId(this.id). Everything *looks* right, but I get a "java.lang.StackOverflowError" when i try to run a simple test to add a positionSkill to a Position.
Any ideas?