-->
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: One-to-One mapping with foreign key been a Entity
PostPosted: Sat Mar 29, 2014 12:07 pm 
Newbie

Joined: Sat Mar 29, 2014 11:54 am
Posts: 1
Hi!

I'm trying to do an one-to-one mapping where the primary key of one entity will be composed of two foreign properties and two local fields...and in the other entity I want that the identifier will be the same as mapped entity..how can I do that?...I will provided a example of the code...I'm using XML mapping

The two entities:

Code:

public interface IResidue {

    public Chain getChain();

    public int getNumber();

    public Character getInsCode();
}

public class Air {

    IResidue residue
   //getter's and setter's for residue
...
}


The entity Air has no own ID, I'm trying to import the ID of IResidue to Air..: that should be the ID of Chain entity: pdb_id,chain_id plus the properties: number,insCode.


here is my XML mapping (removed unimportant code):

Code:

<hibernate-mapping package="br.embrapa.cnptia.cbi.stinglib.descriptors.air">
   <class name="Air" table="Air">

   <composite-id name="residue">         
      <key-many-to-one name="chain" class="br.embrapa.cnptia.cbi.stinglib.core.Chain">
         <column name="pdb_id"/>
         <column name="chain_id"/>                  
      </key-many-to-one>
      <key-property name="number" />
      <key-property name="insCode" >
         <column name="icode" sql-type="varchar(1)"/>
      </key-property>               
      <generator class="foreign">
         <param name="property">residue</param>
      </generator>   
      </composite-id>

      <one-to-one name="residue" class="br.embrapa.cnptia.cbi.stinglib.core.IResidue"  />
   </class>
</hibernate-mapping>

<hibernate-mapping package="br.embrapa.cnptia.cbi.stinglib.core">
   <class name="IResidue" table="Residues">

      <composite-id>
         <key-many-to-one name="chain" class="Chain">
            <column name="pdb_id"/>
            <column name="chain_id"/>                  
         </key-many-to-one>
         <key-property name="number" />
         <key-property name="insCode" >
            <column name="icode" sql-type="varchar(1)"/>
         </key-property>         
      </composite-id>      

      <many-to-one name="chain" class="Chain" insert="false"
         update="false">
         <column name="pdb_id" />
         <column name="chain_id" />
      </many-to-one>

               <property name="name" type="string"/>
   </class>

<!-- join-subclasses -->
<join-subclass ...
.
.
.
</join-subclass>
</hibernate-mapping>



This mapping is not throwing any exception and database tables are correctly created, but when a try to to a HQL like

"from Air air where air.residue.name = 'AAA'"

it does not work: Exception in thread "main" org.hibernate.QueryException: could not resolve property: residue.name of: br.embrapa.cnptia.cbi.stinglib.descriptors.air.Air [from br.embrapa.cnptia.cbi.stinglib.descriptors.air.Air air where air.residue.name = 'ALA']
at org.hibernate.QueryException.generateQueryException(QueryException.java:137)
at org.hibernate.QueryException.wrapWithQueryString(QueryException.java:120)
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:234)
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:158)
at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:126)
at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:88)
at org.hibernate.engine.query.spi.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:190)
at org.hibernate.internal.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:301)
at org.hibernate.internal.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:236)
at org.hibernate.internal.SessionImpl.createQuery(SessionImpl.java:1796)
at br.embrapa.cnptia.cbi.stingcalc.main.StingCalc.main(StingCalc.java:398)

but if I do:
"from Air air where air.residue.number = 1" it works....

I guess that the composite-id of class Air is working correctly, but I can't access fields from IResidue due incorrectly use of composite-id..
How can I do this mapping works???

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.