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!!!
|