-->
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.  [ 5 posts ] 
Author Message
 Post subject: Mapping Exception!
PostPosted: Fri Jun 29, 2007 2:37 am 
Newbie

Joined: Fri Jun 29, 2007 2:34 am
Posts: 2
Location: Pakistan
I am having following exception..i have a unique scnario..primary keys from two tables are going to foreign in the third table and both makes the composite primary key for the third table as well...
i m getting the following exception while mapping


org.hibernate.MappingException: Foreign key (FKF912FC5C2F999B6:insurance_companies_terrifs [elt])) must have same number of columns as the referenced primary key (insurance_companies_terrifs [ins_co_id,elt])
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:1187)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1094)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1210)
at org.springframework.orm.hibernate3.LocalSessionFactoryBean.newSessionFactory(LocalSessionFactoryBean.java:807)
at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:740)
at org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPropertiesSet(AbstractSessionFactoryBean.java:131)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1062)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1029)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:420)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:245)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:141)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:242)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:156)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:287)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:348)
at org.springframework.web.context.support.AbstractRefreshableWebApplicationContext.refresh(AbstractRefreshableWebApplicationContext.java:156)
at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:246)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:184)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:49)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3729)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4187)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:759)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:739)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:524)
at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:608)
at org.apache.catalina.startup.HostConfig.deployDescriptors(HostConfig.java:535)
at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:470)
at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1122)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:310)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1021)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:718)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1013)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:442)
at org.apache.catalina.core.StandardService.start(StandardService.java:450)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:709)
at org.apache.catalina.startup.Catalina.start(Catalina.java:551)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:294)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:432)


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 29, 2007 3:20 am 
Regular
Regular

Joined: Mon Apr 02, 2007 3:54 am
Posts: 67
Location: Hyderabad
Can you send your mappings ?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 29, 2007 3:33 am 
Newbie

Joined: Fri Jun 29, 2007 2:34 am
Posts: 2
Location: Pakistan
table1: insurance_companies
-------------------------------------------------------

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE hibernate-mapping
PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>
<class name="com.aedsys.insurance.model.InsuranceCompaniesImpl" table="insurance_companies" lazy="true">
<id name="ins_co_id" column="ins_co_id">
<generator class="increment" />
</id>
<property name="ins_co_name" column="ins_co_name" />
<property name="ins_co_symbol" column="ins_co_symbol" />
<set name="company_terrifs" table="insurance_companies_terrifs" cascade="all" lazy="true">
<key column="ins_co_id" />
<many-to-many class="com.aedsys.insurance.model.InsuranceCompTerrifsImpl" unique="true" />
</set>
</class>
</hibernate-mapping>
-----------------------------------
table-2 insurance_companies_terrifs
------------------------------------------
<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE hibernate-mapping
PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>
<class name="com.aedsys.insurance.model.InsuranceCompTerrifsImpl" table="insurance_companies_terrifs" lazy="true">

<composite-id name="insuranceCompTerrifsPK" class="com.aedsys.insurance.model.InsuranceCompTerrifsPK">
<key-property name="ins_co_id" column="ins_co_id" />
<key-property name="vechicle_type_id" column="vechicle_type_id" />
</composite-id>
<property name="nill_rate" column="nill_rate" />
<property name="self_declaration" column="self_declaration" />
<property name="one_year" column="one_year" />
<property name="two_year" column="two_year" />
<property name="three_year" column="three_year" />
<property name="five_plus" column="five_plus" />
<property name="age" column="age" />
<property name="nationality_uae" column="nationality_uae" />
<property name="nationality_others" column="nationality_others" />
<property name="uae_dl_convertible" column="uae_dl_convertible" />
<property name="uae_dl_nonconvertible" column="uae_dl_nonconvertible" />
<property name="comp_nationality" column="comp_nationality" />
<property name="comp_dl" column="comp_dl" />
<property name="comp_named_driver" column="comp_named_driver" />
<property name="excess_less_50k" column="excess_less_50k" />
<property name="excess_less_200k" column="excess_less_200k" />
<property name="excess_less_50k" column="excess_less_50k" />
<property name="excess_less_350k" column="excess_less_350k" />
<property name="off_roadcover" column="off_roadcover" />

</class>
</hibernate-mapping>

in table2 there is a vehicle_type_id which is foregin key from another table which is vehicle_type so the composite id for the table2 is foreign key from table vehicle_type and from insurance_companies i-e (insurance_co_id,vehicle_type_id)

thanks for your help


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 29, 2007 5:12 am 
Expert
Expert

Joined: Tue Jan 30, 2007 12:45 am
Posts: 283
Location: India
<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE hibernate-mapping
PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>
<class name="com.aedsys.insurance.model.InsuranceCompaniesImpl" table="insurance_companies" lazy="true">
<id name="ins_co_id" column="ins_co_id">
<generator class="increment" />
</id>
<property name="ins_co_name" column="ins_co_name" />
<property name="ins_co_symbol" column="ins_co_symbol" />
<set name="company_terrifs" table="insurance_companies_terrifs" cascade="all" lazy="true">
<key column="ins_co_id" />
<many-to-many class="com.aedsys.insurance.model.InsuranceCompTerrifsImpl" unique="true" />
</set>
</class>
</hibernate-mapping>


You can't map ID with composite key.This HBM should have composite key rather than ID

_________________
Dharmendra Pandey


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 04, 2007 12:31 am 
Regular
Regular

Joined: Mon Apr 02, 2007 3:54 am
Posts: 67
Location: Hyderabad
Can you send ur pojos also ? May be something wrong for composite key ?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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.