-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Hibernate Association table - extra column
PostPosted: Sun Mar 23, 2008 5:11 am 
Newbie

Joined: Sun Mar 23, 2008 5:03 am
Posts: 3
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]


Top
 Profile  
 
 Post subject: Re: Hibernate Association table - extra column
PostPosted: Mon Mar 24, 2008 10:54 am 
Expert
Expert

Joined: Wed Apr 11, 2007 11:39 am
Posts: 735
Location: Montreal, QC
I thought you needed a class for relations that have attributes.



Farzad-


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.