gavin wrote:
Quote:
The problem in -this- case is that you have mapped a property of type int as a many-to-one association! The property should be of type Parent.
The Child's parentId property was changed to be "parent" (as shown below) but that did not appear to resolve the issue. Now the error is "
Fail to add null value in not null attribute parentid in Child"
Ironically, that was the reason I added
many-to-one property to the Child in the first place; without it HB would try to insert '0' as the Child's parentId or, in other words, when new Parent and Child are created, the parentId is not properly set in the Child.
Any ideas? Thanks
Parent mapping:
Code:
...
<bag name="children"
inverse="true"
lazy="true"
cascade="all">
<key column="parentId"/>
<one-to-many class="test.Child"/>
Child mapping:
Code:
...
<many-to-one name="parent" column="parentId" not-null="true" unique="false"
class="test.Parent"/>
Child class:
Code:
public class Child {
private int childId;
private String name;
private Parent parent;
public Parent getParent() { return parent; }
public void setParent(Parent parentId) { this.parent = parent; }
[...]
// other getters and setters in the same manner
}