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