-->
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 via foreign key
PostPosted: Thu Apr 03, 2008 3:26 am 
Newbie

Joined: Thu Apr 03, 2008 3:13 am
Posts: 2
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:
3.2.6.ga

Mapping documents:
Product.hbm.xml
<hibernate-mapping>
<class name="com.intellect.smartbuy.value.Product" table="product" catalog="smartbuy">
<id name="name" type="string">
<column name="name" length="25" />
<generator class="assigned" />
</id>
<set name="categories" inverse="true">
<key>
<column name="product_name" length="25" not-null="true" />
</key>
<one-to-many class="com.intellect.smartbuy.value.Category" />
</set>
</class>
</hibernate-mapping>

Category.hbm.xml

<hibernate-mapping>
<class name="com.intellect.smartbuy.value.Category" table="category" catalog="smartbuy">
<composite-id>
<key-property name="name" type="string">
<column name="name" length="25" />
</key-property>
<key-many-to-one name="product" class="com.intellect.smartbuy.value.Product">
<column name="product_name" length="25" not-null="true"/>
</key-many-to-one>
</composite-id>
<set name="company" inverse="true">
<key update="false">
<column name="name" length="25" not-null="true" />
<column name="category_name" length="25" not-null="true" />
</key>
<one-to-many class="com.intellect.smartbuy.value.Company"/>
</set>
\<property name="description" type="string">
<column name="description" length="500" />
</property>
</class>
</hibernate-mapping>

Company.hbm.xml
<hibernate-mapping>
<class name="com.intellect.smartbuy.value.Company" table="company" catalog="smartbuy">
<composite-id>
<key-property name="name" type="string">
<column name="name" length="25" not-null="true"/>
</key-property>
<key-many-to-one name="category" class="com.intellect.smartbuy.value.Category">
<column name="category_name" length="25" not-null="true"/>
</key-many-to-one>
</composite-id>

</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():

Full stack trace of any exception that occurs:
Exception in thread "main" org.hibernate.MappingException: Foreign key (FK38A73C7DB02D7C7D:company [category_name])) must have same number of columns as the referenced primary key (category [name,product_name])
at org.hibernate.mapping.ForeignKey.alignColumns(ForeignKey.java:90)
at org.hibernate.mapping.ForeignKey.alignColumns(ForeignKey.java:73)
at org.hibernate.cfg.Configuration.secondPassCompileForeignKeys(Configuration.java:1260)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1167)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1283)
at com.intellect.smartbuy.value.Main.main(Main.java:40)
Name and version of the database you are using:
Server version: 5.0.45-community-nt MySQL Community Edition (GPL)
The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:


Problems with Session and transaction handling?

Read this: http://hibernate.org/42.html


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 03, 2008 10:13 pm 
Newbie

Joined: Thu Apr 03, 2008 3:13 am
Posts: 2
Any help is appreciated....


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.