Hibernate version:3.0
Hi
I am using the hbm.xml files & annotations simultaneously.I have a child collection which can have a set of child objects.The association is unidirectional & one to many(parent child).
While saving the foreign key(primary key of collection ) is not saved in child table. Can anyone please let me know where I am going wrong??
Thanks In Advance.
[b]Mapping documents:
<hibernate-mapping>
<class name="ChildImpl" table="CHILD">
<id name="id" column="CID" >
<generator class="native"/>
</id>
<property name="collectionId"/>
<property name="childObjectId"/>
<!--NOTE::We cannot use order as a property name-->
<property name="proporder"/>
<map name="childProps" table="PROPERTY" lazy="false">
<key column="CID"/>
<index column="key1" type="string"/>
<element type="string" column="value"></element>
</map>
</class>
</hibernate-mapping>
[b]
@Entity(access=AccessType.PROPERTY)
@Table(name="CHILDCOLLECTION")
public class ChildCollectionImpl {
private long id;
private Set childs = new HashSet();
@Id(generate=GeneratorType.IDENTITY)
@Column(name ="CCID")
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
@OneToMany(cascade = CascadeType.ALL,targetEntity="ChildImpl",fetch = FetchType.EAGER)
@JoinColumn(name="CCID",nullable = false)
public Set getChilds() {
return childs;
}
public void setChilds(Set childs) {
this.childs = childs;
}
}
Following are the queries:
Hibernate: insert into CHILDCOLLECTION default values
Hibernate: insert into CHILD (collectionId, childObjectId, proporder) values (?, ?, ?)
StackTrace:
- Cannot insert the value NULL into column 'CCID', table 'Prepopulated.dbo.CHILD'; column does not allow nulls. INSERT fails.
org.hibernate.exception.ConstraintViolationException: could not insert: [ChildImpl]
|