Context : Spring + Hibernate, using the HibernateDaoSupport to perform all the hibernate funtions
Hibernate version:3
Name and version of the database you are using: MS SQL Server 2005.
A Booking can has a list of Shipments:
Below are the xml mapping for booking and Shipments;
<hibernate-mapping package="com.dhl.apis.csvlite.maint.domain">
<class name="Booking" table="booking_details" lazy="false">
<cache usage="read-write" />
<composite-id>
<key-property name="pickupDate"
column="pickup_date"/>
<key-property name="bookRef"
column="book_refnum"/>
<key-property name="bookRev"
column="book_revision"/>
</composite-id>
<property name="bookedBy" column="booked_by" />
<property name="accNo" column="account_number" />
<set name="shipments" lazy="true" inverse="true" cascade="all">
<cache usage="read-write"/>
<key>
<column name="pickup_date"/>
<column name="book_refnum"/>
<column name="book_revision"/>
</key>
<one-to-many class="Shipment"/>
</set>
</class>
</hibernate-mapping>
<hibernate-mapping package="com.dhl.apis.csvlite.maint.domain">
<class name="Shipment" table="book_shipments" lazy="false">
<cache usage="read-write"/>
<composite-id>
<key-many-to-one name="pickupDate"
class="Booking"
column="pickup_date"/>
<key-many-to-one name="bookRev"
class="Booking"
column="book_revision"/>
<key-many-to-one name="bookRef"
class="Booking"
column="book_refnum"/>
</composite-id>
<property name="commodity" column="commodity" />
<property name="transport" column="transport" />
</class>
</hibernate-mapping>
I m using Spring + Hibernate, In the database, i have 2 tables : booking_details and shipments_details
booking_details will have 3 primary, which are
book_refnum
pickup_date
book_revision
book_shipments will have 4 primary key, which are
book_refnum
pickup_date
book_revision
ship_revision
I wanted the application to behave in such a way where i create a Booking and manually insert all the required primary key, then i create a Shipment object by only populate the ship_revision and add to the Booking object, and hoping hibernate will auto insert the remaining 3 primary key from Booking object.
But i have the following problem when i load it into tomcat :
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mySessionFactory' defined in Ser
vletContext resource [/WEB-INF/applicationContext.xml]: Initialization of bean failed; nested exception is org.hibernate
.MappingException: Foreign key (FK608A28436D7F4927:book_shipments [book_refnum])) must have same number of columns as th
e referenced primary key (booking_details [pickup_date,book_refnum,book_revision])
org.hibernate.MappingException: Foreign key (FK608A28436D7F4927:book_shipments [book_refnum])) must have same number of
columns as the referenced primary key (booking_details [pickup_date,book_refnum,book_revision])
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:1097)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1036)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1120)
at org.springframework.orm.hibernate3.LocalSessionFactoryBean.newSessionFactory(LocalSessionFactoryBean.java:777
)
at org.springframework.orm.hibernate3.LocalSessionFactoryBean.afterPropertiesSet(LocalSessionFactoryBean.java:70
3)
Can anyone pls help out.
thank you.
|