net.sf.hibernate.MappingException

There are no available Samebug tips for this exception. Do you have an idea how to solve this issue? A short tip would help users who saw this issue last week.

  • I have two tables, QWB_EXTRCT_VW_CLMN and QWB_FLDR_CLMN. QWB_EXTRCT_VW_CLMN has a composite primary key with columns EXTRCT_VW_NUM and FLDR_CLMN_NUM, FLDR_CLMN_NUM being a foreign key to the (single) primary key of the QWB_FLDR_CLMN table. Middlegen generates the following mapping for QwbFldrClmn: <composite-id name="comp_id" class="testQwb.hibernate.persistent.QwbExtrctVwClmnPK"> <meta attribute="field-description"> @hibernate.id generator-class="assigned" </meta> <!-- uni-directional one-to-one association to QwbFldrClmn --> <key-many-to-one name="qwbFldrClmn" class="testQwb.hibernate.persistent.QwbFldrClmn" > <column name="FLDR_CLMN_NUM" /> </key-many-to-one> <!-- bi-directional many-to-one association to QwbExtrctVw --> <key-many-to-one name="qwbExtrctVw" class="testQwb.hibernate.persistent.QwbExtrctVw" > <column name="EXTRCT_VW_NUM" /> </key-many-to-one> </composite-id> However when run the following exception is thrown: net.sf.hibernate.MappingException: Foreign key (QWB_EXTRCT_VW_CLMN [FLDR_CLMN_NUM])) must have same number of columns as the reference primary key (QWB_FLDR_CLMN [FLDR_NUM,FLDR_CLMN_NUM]) at net.sf.hibernate.mapping.ForeignKey.setReferencedTable(ForeignKey.java:60) at net.sf.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:625) at net.sf.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:719) at org.ifmc.qw.hibernate.HibernateSession.init(HibernateSession.java:44) at testQwb.hibernate.TestHibernate3.main(TestHibernate3.java:22) Note that this xml works with the 2.1 beta 6, but not with RC1. Is Middlegen not putting something in? BTW in general I am having a heck of a time migrating from 2.1 Beta 6 to RC1 using Middlegen created XML files. Seems to me to be a good idea to do more testing with Middlegen and Hibernate to make sure the generated files work. Or else modify Hibernate or Middlegen so they would cooperate better. Also please note that this is NOT the same problem as with HB-512, I am already using the patched code but yet I now have this new error. Thanks, Daniel
    via by Daniel Rosenbaum,
  • I have two tables, QWB_EXTRCT_VW_CLMN and QWB_FLDR_CLMN. QWB_EXTRCT_VW_CLMN has a composite primary key with columns EXTRCT_VW_NUM and FLDR_CLMN_NUM, FLDR_CLMN_NUM being a foreign key to the (single) primary key of the QWB_FLDR_CLMN table. Middlegen generates the following mapping for QwbFldrClmn: <composite-id name="comp_id" class="testQwb.hibernate.persistent.QwbExtrctVwClmnPK"> <meta attribute="field-description"> @hibernate.id generator-class="assigned" </meta> <!-- uni-directional one-to-one association to QwbFldrClmn --> <key-many-to-one name="qwbFldrClmn" class="testQwb.hibernate.persistent.QwbFldrClmn" > <column name="FLDR_CLMN_NUM" /> </key-many-to-one> <!-- bi-directional many-to-one association to QwbExtrctVw --> <key-many-to-one name="qwbExtrctVw" class="testQwb.hibernate.persistent.QwbExtrctVw" > <column name="EXTRCT_VW_NUM" /> </key-many-to-one> </composite-id> However when run the following exception is thrown: net.sf.hibernate.MappingException: Foreign key (QWB_EXTRCT_VW_CLMN [FLDR_CLMN_NUM])) must have same number of columns as the reference primary key (QWB_FLDR_CLMN [FLDR_NUM,FLDR_CLMN_NUM]) at net.sf.hibernate.mapping.ForeignKey.setReferencedTable(ForeignKey.java:60) at net.sf.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:625) at net.sf.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:719) at org.ifmc.qw.hibernate.HibernateSession.init(HibernateSession.java:44) at testQwb.hibernate.TestHibernate3.main(TestHibernate3.java:22) Note that this xml works with the 2.1 beta 6, but not with RC1. Is Middlegen not putting something in? BTW in general I am having a heck of a time migrating from 2.1 Beta 6 to RC1 using Middlegen created XML files. Seems to me to be a good idea to do more testing with Middlegen and Hibernate to make sure the generated files work. Or else modify Hibernate or Middlegen so they would cooperate better. Also please note that this is NOT the same problem as with HB-512, I am already using the patched code but yet I now have this new error. Thanks, Daniel
    via by Daniel Rosenbaum,
  • I've generated two hbm with Middlegen with a simple one-to-one relation: A first object with a composite 2 field key, and 10 other plain properties, and another object with a normal long key and two properties. The declaration on the relation in the first object is: <many-to-one name="commento" class="Commento" unique="false" insert="false" update="false" > <column name="MLCOM" /> </many-to-one> In the other object: <one-to-one name="marelo" class="Marelo" outer-join="auto" property-ref="commento" /> When I ask any page of the application, I get an error during Hibernate session's initialization. Here's the stack trace: 16:20:54,849 ERROR HibernateSessionFactory:35 - error configuring net.sf.hibernate.MappingException: bug in initComponentPropertyPaths at net.sf.hibernate.persister.AbstractPropertyMapping.initComponentPropertyPaths(AbstractPropertyMapping.java:140) at net.sf.hibernate.persister.AbstractPropertyMapping.initPropertyPaths(AbstractPropertyMapping.java:111) at net.sf.hibernate.persister.AbstractPropertyMapping.initPropertyPaths(AbstractPropertyMapping.java:80) at net.sf.hibernate.persister.AbstractEntityPersister.initPropertyPaths(AbstractEntityPersister.java:515) at net.sf.hibernate.persister.EntityPersister.postInstantiate(EntityPersister.java:110) at net.sf.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:156) at net.sf.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:750) at cinetica.hibernate.web.component.HibernateSessionFactory.init(HibernateSessionFactory.java:32) [snip] Caused by: java.lang.ArrayIndexOutOfBoundsException: 1 at net.sf.hibernate.util.ArrayHelper.slice(ArrayHelper.java:61) at net.sf.hibernate.persister.AbstractPropertyMapping.initComponentPropertyPaths(AbstractPropertyMapping.java:135) ... 52 more
    via by Marco Papini,
  • I have three tables (each has a composite key). I get following message exception during mapping processing. net.sf.hibernate.MappingException: Repeated column in mapping for collection: test.User.points column: HO_ID at net.sf.hibernate.collection.AbstractCollectionPersister.checkColumnDuplication(AbstractCollectionPersister.java:652) at net.sf.hibernate.collection.AbstractCollectionPersister.<init>(AbstractCollectionPersister.java:206) at net.sf.hibernate.collection.BasicCollectionPersister.<init>(BasicCollectionPersister.java:36) at net.sf.hibernate.persister.PersisterFactory.createCollectionPersister(PersisterFactory.java:55) at net.sf.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:147) at net.sf.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:791) SCHEMA DEFINITION ----------------- Table: M_USER - HO_ID (PK) - KA_ID (PK) - NAME Table: M_YEAR - HO_ID (PK) - YEAR_ID (PK) - Q_DATE Table: POINT - HO_ID (PK,FK) - KA_ID (PK,FK) - YEAR_ID (PK,FK) - POINT MAPPING FILE ------------ <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 2.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd"> <hibernate-mapping > <class name="test.User" table="M_USER" > <composite-id name="comp_id" class="test.UserPK" > <key-property name="hoId" type="java.lang.String" column="HO_ID" /> <key-property name="kaId" type="java.lang.String" column="KA_ID" /> </composite-id> <property name="name" type="java.lang.String" column="NAME" length="20" /> <map name="points" table="POINT" lazy="false" sort="unsorted" cascade="none" > <key> <column name="HO_ID"/> <column name="KA_ID"/> </key> <index-many-to-many class="test.Year" > <column name="HO_ID"/> <column name="YEAR_ID"/> </index-many-to-many> <composite-element class="test.Point"> <property name="point" type="java.lang.Integer" column="POINT" length="3" /> </composite-element> </map> </class> </hibernate-mapping>
    via by Yoshitaka Takamura,
  • Error Description ------------------------ %%%% Error Creating SessionFactory %%%% net.sf.hibernate.MappingException: collection foreign key mapping has wrong number of columns: com.tsystems.ecm.imaes.imadb.hibernate2.archive.ImsTable.archiveFiles type: com.tsystems.ecm.imaes.imadb.hibernate2.archive.ImsTablePK at net.sf.hibernate.mapping.Collection.validate(Collection.java:248) at net.sf.hibernate.cfg.Configuration.validate(Configuration.java:589) at net.sf.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:744) at helper.HibernateSession.currentSession(HibernateSession.java:52) at com.tsystems.ecm.imaes.imadb.hibernate2.archive.ImsTableDAO.save(ImsTableDAO.java:28) at test.ImsTableTest.testSaveDFolder(ImsTableTest.java:78) 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:324) at junit.framework.TestCase.runTest(TestCase.java:154) at junit.framework.TestCase.runBare(TestCase.java:127) 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 junit.framework.TestSuite.runTest(TestSuite.java:208) at junit.framework.TestSuite.run(TestSuite.java:203) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:474) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:342) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:194) -------------------------------------------------------------------------------------------------------------------------------------------------------- Hibernate Mapping Files --------------------------------- See the attachment for 1. ImsSpecTable.hbm.xml 2. ImsTable.hbm.xml Database Table Structure ------------------------------------ 1. Table_Structure.gif
    via by Mohammed Mazhar Shaikh,
    • net.sf.hibernate.MappingException: Foreign key (QWB_EXTRCT_VW_CLMN [FLDR_CLMN_NUM])) must have same number of columns as the reference primary key (QWB_FLDR_CLMN [FLDR_NUM,FLDR_CLMN_NUM]) at net.sf.hibernate.mapping.ForeignKey.setReferencedTable(ForeignKey.java:60) at net.sf.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:625) at net.sf.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:719) at org.ifmc.qw.hibernate.HibernateSession.init(HibernateSession.java:44) at testQwb.hibernate.TestHibernate3.main(TestHibernate3.java:22)
    No Bugmate found.