Im getting an exception after trying to test my hibernate mapping. The tables looks something like this:
TABLE a
a
b
primary key (a, b)
foreign key (b) on (c.a)
TABLE b
a
b
c
primary key (a)
foreign key (b, c) on (a.a, a.b)
TABLE c
a
b
c
primary key(a)
Table A's mapping:
Code:
<class name="ProductType" table="PRODUCT_TYPES">
<composite-id name="id" class="ProductTypeKey">
<key-many-to-one name="product" column="PTYP_PRODUCT_CODE" class="Product"/>
<key-property name="ptypProductType" column="PTYP_PRODUCT_TYPE" type="java.lang.String"/>
</composite-id>
.....
Table B's mapping looks something like:
Code:
<class name="PartnerAgreement" table="PARTNER_AGREEMENTS">
<id name="agreAgreementNumber" column="AGRE_AGREEMENT_NUMBER" type="java.lang.Integer">
<generator class="native"/>
</id>
<many-to-one name="productType" column="AGRE_PRODUCT_CODE" class="ProductType" not-null="true" />
<many-to-one name="productType1" column="AGRE_PRODUCT_TYPE" class="ProductType" not-null="true" />
How do I map AGRE_PRODUCT_CODE and AGRE_PRODUCT_TYPE for table B which are the primary composite key from table a? Is what I've done correct. Im getting the exception below.
Hibernate version: 3.0
Full stack trace of any exception that occurs:Code:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [spring-context.xml]: Initialization of bean failed; nested exception is org.hibernate.MappingException: Foreign key (FKA0044FA0EE76CD:PARTNER_AGREEMENTS [AGRE_PRODUCT_TYPE])) must have same number of columns as the referenced primary key (PRODUCT_TYPES [PTYP_PRODUCT_CODE,PTYP_PRODUCT_TYPE])
org.hibernate.MappingException: Foreign key (FKA0044FA0EE76CD:PARTNER_AGREEMENTS [AGRE_PRODUCT_TYPE])) must have same number of columns as the referenced primary key (PRODUCT_TYPES [PTYP_PRODUCT_CODE,PTYP_PRODUCT_TYPE])
at org.hibernate.mapping.ForeignKey.alignColumns(ForeignKey.java:86)
at org.hibernate.mapping.ForeignKey.setReferencedTable(ForeignKey.java:51)
at org.hibernate.cfg.Configuration.secondPassCompileForeignKeys(Configuration.java:976)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:921)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:999)
at org.springframework.orm.hibernate3.LocalSessionFactoryBean.newSessionFactory(LocalSessionFactoryBean.java:767)
at org.springframework.orm.hibernate3.LocalSessionFactoryBean.afterPropertiesSet(LocalSessionFactoryBean.java:693)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1003)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:348)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:226)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:147)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:269)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:317)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:80)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:65)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:56)
at tuinsurance.lib.integration.dao.impl.HibRateTripFactorTest.setUp(HibRateTripFactorTest.java:21)
at junit.framework.TestCase.runBare(TestCase.java:125)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:478)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:344)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
Name and version of the database you are using: Oracle 9i