-->
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.  [ 4 posts ] 
Author Message
 Post subject: Id from composite foreign key
PostPosted: Mon May 02, 2005 6:56 am 
Beginner
Beginner

Joined: Mon Apr 11, 2005 8:37 am
Posts: 22
Hibernate version:
3.0

Mapping documents:


ActResEmploy:
Code:
  <class table="ACT_RES_EMPLOY" name="ActResEmploy" discriminator-value="NOS">
    <meta attribute="class-description" inherit="false">@hibernate.class table="ACT_RES_EMPLOY"</meta>

<!-- Not sure whether that will work (in combination with one-to-one relation at the bottom) -->
    <id>
       <column name="ACT_RES_IX" sql-type="long"/>
       <column name="ACT_ID" sql-type="long"/>
      <generator class="foreign">
        <param name="property">actRes</param>
      </generator>
    </id>
   
<!-- Associations -->
    <one-to-one name="actRes" class="ActRes" outer-join="auto" constrained="true" property-ref="ActResCompositeKey">
      <meta attribute="field-description">@hibernate.one-to-one class="ActRes" outer-join="auto" constrained="true"</meta>
    </one-to-one>
  </class>


ActRes:
Code:
  <class table="ACT_RES" name="ActRes" >
    <meta attribute="class-description" inherit="false">@hibernate.class table="ACT_RES"</meta>
    <id name="actResIx" type="long" column="ACT_RES_IX" length="15">
      <meta attribute="field-description">@hibernate.id generator-class="GH4IdGenerator" type="long" column="ACT_RES_IX" length="15"</meta>
      <generator class="GH4IdGenerator">
        <param name="sequence">act_res_index_seq</param>
        <param name="GH4IdType">Prefix</param>
      </generator>
    </id>
   
      <properties name="ActResCompositeKey" unique="true" insert="false" update="false">
       <property name="actResIx" type="java.lang.Long" column="ACT_RES_IX" length="15" insert="false" update="false">
         <meta attribute="field-description">@hibernate.property column="ACT_RES_IX" length="15"</meta>
       </property>
       <property name="actId" type="java.lang.Long" column="ACT_ID" length="15" insert="false" update="false">
         <meta attribute="field-description">@hibernate.property column="ACT_ID" length="15"</meta>
       </property>
      </properties>


<!-- Associations -->
<!-- derived association(s) for compound key -->
<!-- bi-directional many-to-one association to Act -->
    <many-to-one name="act" class="Act" update="true" insert="true">
      <meta attribute="field-description">@hibernate.many-to-one update="true" insert="true"</meta>
      <meta attribute="field-description">@hibernate.column name="ACT_ID"</meta>
      <column name="ACT_ID" />
    </many-to-one>
<!-- end of derived association(s) -->
<!-- bi-directional one-to-one association to ActResEmploy -->
    <one-to-one name="actResEmploy" class="ActResEmploy" outer-join="auto" property-ref="ActResCompositeKey">
      <meta attribute="field-description">@hibernate.one-to-one outer-join="auto"</meta>
    </one-to-one>
  </class>


Full stack trace of any exception that occurs:
Code:
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: Error reading resource: ActResEmploy.hbm.xml
   at org.hibernate.cfg.Configuration.addResource(Configuration.java:447)
   at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:1381)
   at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1353)
   at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1335)
   at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1302)
   at org.hibernate.cfg.Configuration.configure(Configuration.java:1230)
   at org.hibernate.cfg.Configuration.configure(Configuration.java:1216)
   at c2iedm.hibernate.util.HibernateConnectionSingleton.<clinit>(HibernateConnectionSingleton.java:28)
   ... 3 more
Caused by: org.hibernate.MappingException: must specify an identifier type: ActResEmploy
   at org.hibernate.cfg.HbmBinder.bindSimpleId(HbmBinder.java:352)
   at org.hibernate.cfg.HbmBinder.bindRootPersistentClassCommonValues(HbmBinder.java:291)
   at org.hibernate.cfg.HbmBinder.bindRootClass(HbmBinder.java:233)
   at org.hibernate.cfg.HbmBinder.bindRoot(HbmBinder.java:149)
   at org.hibernate.cfg.Configuration.add(Configuration.java:358)
   at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:395)
   at org.hibernate.cfg.Configuration.addResource(Configuration.java:444)
   ... 10 more
Exception in thread "main"


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

The generated SQL (show_sql=true):
didn't get so far...

What am I supposed to do? Is it possible at all to use a composite property as foreign identifier? I haven't found anything explicit about that, but also no examples...
I hope somebody can help me with that - I'm pretty much stuck!


Top
 Profile  
 
 Post subject: Same Problem.
PostPosted: Thu Jun 09, 2005 11:40 am 
Newbie

Joined: Sun Aug 01, 2004 8:23 pm
Posts: 11
I am pretty much in the same boat. Have you gotten anywhere on this yet. In the meantime, I am essentially constructing a key and doing a Session.get() to retrieve the 1-1 related entiity. It is annoying. I am doing this in 2.1 but my error is the same as yours.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 10, 2005 5:25 am 
Beginner
Beginner

Joined: Mon Apr 11, 2005 8:37 am
Posts: 22
Well, I have changed the mapping of ActRes. I now declare a composite-id that looks like the <properties> element before. ActResEmploy uses the same key (same class). That way I can't use the id-generator for my property actResIx. I had to edit the Java source of the key class, so that on instantiation of a key object the id is generated from the database sequence by an SQL query ("select " + sequenceName + ".NEXTVAL from dual"). Not perfect but it works (has no performance loss: hibernate does the same query - that's how I got the idea).
Maybe it helps ...


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 10, 2005 5:30 am 
Beginner
Beginner

Joined: Mon Apr 11, 2005 8:37 am
Posts: 22
forget to mention:
my first idea was to specify a <sql-insert> that uses database sequences - but then I came across this problem:
http://forum.hibernate.org/viewtopic.php?t=942144


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