- This topic has 2 replies, 2 voices, and was last updated 19 years ago by Brian Fernandes.
-
AuthorPosts
-
jakim8915MemberI created the mapping files through MyEclipse database explorer. 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:
<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:
<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" />
Basically, table b has 2 fields (AGRE_PRODUCT_CODE, AGRE_PRODUCT_TYPE) that are foreign keys to table a’s primary composite key. Any suggestions on why the myeclipse generated mapping doesnt work?
Full stack trace of any exception that occurs:
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)
Im using MyEclipse 4.0 M3 and Hibernate 3 againts Oracle 9i db.
jakim8915MemberWhen Myeclipse generates the hibernate mapping, it generated this:
<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” />
It should have been like this:
<many-to-one name=”productType” class=”ProductType” not-null=”true” >
<column name=”AGRE_PRODUCT_CODE”/>
<column name=”AGRE_PRODUCT_TYPE”/>
</many-to-one>The mapping exception for foreign key goes away.
Brian FernandesModeratorjakim,
Thank you for that report. This is a shortcoming of our current mapping generation solution.
We plan to enhance and correct the mapping generation for our next release – MyEclipse 4.1 and a Visual Mapper will be available shortly after that which will allow you fine grained control over the mapping files generated.Sorry for the inconvenience caused,
Brian. -
AuthorPosts