-->
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.  [ 3 posts ] 
Author Message
 Post subject: Using natural-id in many-to-one relation
PostPosted: Wed Dec 26, 2007 10:56 am 
Beginner
Beginner

Joined: Tue Oct 30, 2007 7:57 am
Posts: 47
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

hibernate 3.0

I have mapped a many-to-one relation between 2 tables, using 2 different columns. Class EVNAmbito is the one part. To implement the relation, I declared a properties set, named idnatural.

Mapping documents:

Code:
<class name="EVNAmbito" table="TBREVTAMBITO" lazy="false" catalog="MAPEVN_PROP" mutable="false">
       <id name="id" type="string" column="CDAMBITO" length="16">
            <generator class="assigned" />       
       </id>

      <properties name="idnatural">      
          <many-to-one name="organismoDestino" class="EVNOrganismoDestino" column="CDORGANISMODEST" fetch="join" not-null="true" />       
          <many-to-one name="tipoAsunto" class="EVNTipoAsunto" column="CDTIPOASUNTO" fetch="join" not-null="true" />          
      </properties>
</class>


Code:

       <!-- Relación de sólo lectura. Necesaria para filtrar usando la lista de ámbitos permitidos al usuario -->
       <many-to-one name="ambito" class="EVNAmbito" property-ref="idnatural" insert="false" update="false" fetch="select">
          <column name="CDORGDESTINO"/>
          <column name="CDTIPOASUNTO"/>
       </many-to-one>



The thing, is that those 2 properties, form also the natural-id of the class, so I'd like to declare the natural-id, and use it for the relation, instead of the properties. The problem I have, is that I don't know how to refer two the natural-id in the many side. I tried with natural-id, naturalId, naturalid in the property-ref, but does not work. Code should be someting like:


Code:
<class name="EVNAmbito" table="TBREVTAMBITO" lazy="false" catalog="MAPEVN_PROP" mutable="false">
       <id name="id" type="string" column="CDAMBITO" length="16">
            <generator class="assigned" />       
       </id>

      <natural-id mutable="false">
          <many-to-one name="organismoDestino" class="EVNOrganismoDestino" column="CDORGANISMODEST" fetch="join" not-null="true" />       
          <many-to-one name="tipoAsunto" class="EVNTipoAsunto" column="CDTIPOASUNTO" fetch="join" not-null="true" />          
      </natural-id>
</class>


Code:

       <!-- Relación de sólo lectura. Necesaria para filtrar usando la lista de ámbitos permitidos al usuario -->
       <many-to-one name="ambito" class="EVNAmbito" property-ref="???????" insert="false" update="false" fetch="select">
          <column name="CDORGDESTINO"/>
          <column name="CDTIPOASUNTO"/>
       </many-to-one>



Is possible to do that?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 26, 2007 3:11 pm 
Newbie

Joined: Thu Aug 16, 2007 3:02 am
Posts: 12
Location: Banglore
Hi,
Can you please tell me what is the problem in gouping those many-to one eleements as properties?This <propertes ></Properties> tag is using only for grouping.even after grouping we can refer these many-to-one relation as like independent fields.


This is possible through formula join


<properties name="idnatural">
<many-to-one name="organismoDestino" class="EVNOrganismoDestino" column="CDORGANISMODEST" fetch="join" not-null="true" />
<many-to-one name="tipoAsunto" class="EVNTipoAsunto" column="CDTIPOASUNTO" fetch="join" not-null="true" />
</properties>


<many-to-one name="ambito" class="EVNAmbito" property- ref="idnatural" insert="false" update="false" fetch="select">
<formula>CDORGDESTINO</formul>
<formul>CDTIPOASUNTO"<formula/>
</many-to-one>

_________________
sirajulmuneer


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 26, 2007 4:23 pm 
Beginner
Beginner

Joined: Tue Oct 30, 2007 7:57 am
Posts: 47
It works perfectly with properties. I just wanted to make use of the natural-id property, because those two many-to-one inside the properties tag, make a perfect unique key.

So I wandered if it was possible to refer to natural-id in joins. If it isn't, no matter, I will keep using properties.


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