Hello,
I'm new to hibernate and am stuck on this issue for sometime now and would really appreciate some help.
I have two tables - GROUP and PRODUCT
Its a many to many association between them.
A group can have many products
A product can belong to many groups
So I have a join table - GROUP_PRODUCT which has groupID and productID.
But it also has an extra column userID
This is what I have added in my Group.hbm.xml file for this purpose
Code:
<set name="products" table="GROUP_PRODUCT" inverse="true" lazy="false">
<key column="GROUPID"/>
<composite-element class="qwicket.myapp.model.GroupProduct">
<property name="userId" type="long" not-null="true"/>
<many-to-one name="product" class="qwicket.myapp.model.Product"/>
</composite-element>
</set>
This is what I have product.hbm.xml for this purpose
Code:
<set name="groups" table="GROUP_PRODUCT" lazy="false">
<key column="PRODUCTID"/>
<many-to-many column="GROUPID" class="qwicket.myapp.model.Group"/>
</set>
Now when I try to create a group and add a product to this group, I see the following sql statements followed by this error:
Code:
Hibernate: insert into GROUPS (GROUPNAME, DESCRIPTION, CLOSEDATE, ID) values (?, ?, ?, ?)
Hibernate: insert into GROUP_PRODUCT (PRODUCTID, GROUPID) values (?, ?)
java.sql.BatchUpdateException: Field 'userId' doesn't have a default value
If you look at the 2nd sql,the insert statement does not even include the extra field userID
I know I'm missing something very basic here. So if you could point me in the right direction - I would greatly appreciate it.
Thanks[/code]