-->
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: proper usage of property-ref - what does foreign-key?
PostPosted: Tue May 03, 2005 8:09 am 
Beginner
Beginner

Joined: Mon Apr 11, 2005 8:37 am
Posts: 22
How can that happen? I define a set of unique attributes with a <properties> element in Cgtdet and try to reference it by property-ref from ActObjve. But instead, hibernate tells me that the number of columns of the referenced primary key (!!) is wrong. Surely it doesn't match - but that's why I want to use the alternate key "CtgtdetCompositeKey" as stated. I'm really confused - has anybody referenced composite alternate keys with the property-ref yet? Is it supposed to work?

Or what am I doing wrong? Please help me! Has it something to do with the attribute foreign-key, which is included in the <key> and <many-to-one> elements (as stated in dtd), but is nowhere in the docu explained.

I would appreciate a comment from the hibernate team! Thanks a lot.


Hibernate version:
3.02

Mapping documents:
( I have removed all irrelevant properties and associations)

Code:
   <class name="Ctgtdet" table="CTGTDET" discriminator-value=" ">
    <id name="ctgtdetIx" type="long" column="CTGDET_IX" length="15">
      <generator class="GH4IdGenerator">
        <param name="sequence">ctgtdet_index_seq</param>
        <param name="GH4IdType">Prefix</param>
      </generator>
    </id>
   
    <discriminator column="catCode"/>

      <properties name="CtgtdetCompositeKey" unique="true" insert="false" update="false">
       <property name="ctgtdetIx" type="java.lang.Long" column="CTGDET_IX" length="15" insert="false" update="false" />
       <property name="ctgtlist" type="java.lang.Long" column="CTGTLST_ID" length="15" insert="false" update="false" />
      </properties>
   
    <many-to-one name="ctgtlst" class="Ctgtlst" update="true" insert="true">
      <column name="CTGTLST_ID" />
    </many-to-one>

       <set name="actObjves" lazy="true" inverse="true" cascade="none">
         <key>
           <column name="CTGTDET_IX" />
           <column name="CTGTLST_ID" />   
         </key>
         <one-to-many class="ActObjve" />
       </set>

  </class>



Code:
  <class table="ACT_OBJVE" name="ActObjve">
    <id name="actObjveIx" type="long" column="ACT_OBJVE_IX" length="15">
      <generator class="GH4IdGenerator">
        <param name="sequence">act_objve_index_seq</param>
        <param name="GH4IdType">Prefix</param>
      </generator>
    </id>
   
      <properties name="ActObjveCompositeKey" unique="true" insert="false" update="false">
       <property name="actObjveIx" type="java.lang.Long" column="ACT_OBJVE_IX" length="15" insert="false" update="false"/>
       <property name="act" type="java.lang.Long" column="ACT_ID" length="15" insert="false" update="false"/>
      </properties>
 
    <many-to-one name="ctgtdet" class="Ctgtdet" not-null="true" property-ref="CtgtdetCompositeKey">
      <column name="CTGTDET_IX" />
      <column name="CTGTLST_ID" />
    </many-to-one>

    <many-to-one name="act" class="Act" update="true" insert="true">
      <column name="ACT_ID" />
    </many-to-one>

  </class>


Full stack trace of any exception that occurs:

java.lang.ExceptionInInitializerError
at util.HibernateConnectionSingleton.<clinit>(HibernateConnectionSingleton.java:31)
at test.Example.init(Example.java:36)
at test.Example.<init>(Example.java:32)
at test.Example.main(Example.java:193)
Caused by: org.hibernate.MappingException: Foreign key (FKD76F23B9F6DE3D43:ACT_OBJVE [CTGTDET_IX,CTGTLST_ID])) must have same number of columns as the referenced primary key (CTGTDET [CTGDET_IX])
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:953)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:898)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1049)
at util.HibernateConnectionSingleton.<clinit>(HibernateConnectionSingleton.java:28)
... 3 more
Exception in thread "main"

Name and version of the database you are using:
Oracle 9

Debug level Hibernate log excerpt:
4437 INFO [main] org.hibernate.cfg.Configuration - processing association property references


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.