-->
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.  [ 1 post ] 
Author Message
 Post subject: Foreig key must have same number of columns as the reference
PostPosted: Mon Jan 16, 2012 10:30 am 
Newbie

Joined: Mon Jan 16, 2012 10:24 am
Posts: 1
Hello!

I developing a web application with NetBeans. I'm trying to integrate hibernate into my project in order to set/get information from Database.

After create the Hibernate Reverse Engigeering file and Mapping Files, using NetBEans wizard, I found one proplem executing HQL:
org.hibernate.MappingException: Foreign key (FK637007E11D64F93:muxes [location_id])) must have same number of columns as the referenced primary key (locations [name,network_name,network_type_id,country_id])
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:1263)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1170)
at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:324)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1286)
at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:859)

My table "locations" has 4 columns for primary key, but my table "muxes" has reference to location id in order to be unique, but NetBeans wizard has created incorrect mapping files, because HQL is giving this problem. Can you help me with this problem?? which modification I have to do on the mapping files in order to use correctly HQL???

And the maping files are:
Muxes.hbm.xml

<hibernate-mapping>
<class name="etna.test.Muxes" table="muxes" catalog="etna">
<composite-id name="id" class="etna.test.MuxesId">
<key-property name="locationId" type="int">
<column name="location_id" />
</key-property>
<key-property name="frequency" type="int">
<column name="frequency" />
</key-property>
</composite-id>
<many-to-one name="locations" class="etna.test.Locations" update="false" insert="false" fetch="select">
<column name="location_id" not-null="true" />
</many-to-one>
<property name="id_1" type="int">
<column name="id" not-null="true" unique="true" />
</property>
<property name="tsid" type="string">
<column name="tsid" length="45" not-null="true" />
</property>
<property name="onid" type="string">
<column name="onid" length="45" not-null="true" />
</property>
<property name="tsLink" type="string">
<column name="ts_link" length="256" not-null="true" />
</property>
</class>
</hibernate-mapping>

Locations.hbm.xml

<hibernate-mapping>
<class name="etna.test.Locations" table="locations" catalog="etna">
<composite-id name="id" class="etna.test.LocationsId">
<key-property name="name" type="string">
<column name="name" length="45" />
</key-property>
<key-property name="networkName" type="string">
<column name="network_name" length="45" />
</key-property>
<key-property name="networkTypeId" type="int">
<column name="network_type_id" />
</key-property>
<key-property name="countryId" type="int">
<column name="country_id" />
</key-property>
</composite-id>
<many-to-one name="countries" class="etna.test.Countries" update="false" insert="false" fetch="select">
<column name="country_id" not-null="true" />
</many-to-one>
<many-to-one name="networks" class="etna.test.Networks" update="false" insert="false" fetch="select">
<column name="network_type_id" not-null="true" />
</many-to-one>
<property name="id_1" type="int">
<column name="id" not-null="true" unique="true" />
</property>
<property name="hostname" type="string">
<column name="hostname" length="45" not-null="true" />
</property>
<property name="latitude" type="float">
<column name="latitude" precision="12" scale="0" not-null="true" />
</property>
<property name="longitude" type="float">
<column name="longitude" precision="12" scale="0" not-null="true" />
</property>
<property name="active" type="boolean">
<column name="active" not-null="true" />
</property>
<set name="muxeses" inverse="true">
<key>
<column name="location_id" not-null="true" />
</key>
<one-to-many class="etna.test.Muxes" />
</set>
</class>
</hibernate-mapping>


Can someone help meee???
Thanks!!!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.