-->
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: Mapping collection with other property that primary key
PostPosted: Fri Feb 16, 2007 8:31 am 
Newbie

Joined: Mon Nov 06, 2006 5:45 am
Posts: 5
I want mapped in file mapping (Product.hbm.xml --> Product.java) a collection with a property naturalId that not the primary key...Collection items are object mapped with a <composite-id> (Product_DopingClassification.hbm.xml --> Product_DopingClassification.java)

But when I save PRODUCT, the relation between this two items is made with the primary key of PRODUCT and not with the property naturalId...
Then my question is : how can I mappe this relation ?
Please...


Hibernate version:
3.13

Mapping documents:
Product.hbm.xml
Code:
<class name="com.vidal.bo.model.product.Product" table="product">
      
      <id name="id" type="long" column="id">
         <generator class="increment"/>
         </id>
     
         <property name="naturalId" type="integer" column="product_Id"/>
[...]
                        <!-- product_dopingClassification link -->
         <set name="product_dopingClassification_set" lazy="false" cascade="all" inverse="true">
             <key column="product_id" property-ref="naturalId"/>
             <one-to-many class="com.vidal.bo.model.product.dopingProduct.Product_DopingClassification" />
          </set>
[...]

Product_DopingClassification.hbm.xml
Code:
<hibernate-mapping>
   <class name="com.vidal.bo.model.product.dopingProduct.Product_DopingClassification" table="product_dopingClassification">
      
      <composite-id>
         <key-many-to-one name="product" class="com.vidal.bo.model.product.Product" column="product_Id" lazy="false"/>
          <key-many-to-one name="dopingClassification" class="com.vidal.bo.model.dictionary.molecule.dopingMolecule.DopingClassification" column="dopingClassification_Id" lazy="false" />
         <key-many-to-one name="versionIn" class="com.vidal.bo.model.versioning.domain.EntityVersion" column="vIn" lazy="false"/>
      </composite-id>
      
      <property name="isValid" type="true_false" column="isValid" />
      
      <!-- many-to-one name="versionIn" column="vIn" class="com.vidal.bo.model.versioning.domain.EntityVersion"/ -->
        <many-to-one name="versionOut" column="vOut" class="com.vidal.bo.model.versioning.domain.EntityVersion"/>

   </class>
</hibernate-mapping>



Code between sessionFactory.openSession() and session.close():
Code:
Product product = new Product();
      product.setName("product name NIASPAN in Version 1");
      Product_DopingClassification productDopingClassification = new Product_DopingClassification();
      productDopingClassification.setProduct(product);
      productDopingClassification.setDopingClassification(currentEntitiesDopingClassification.get(0));
      product.getProduct_dopingClassification_set().add(productDopingClassification);
      productDao.saveOrUpdate(product);


Full stack trace of any exception that occurs:

No explicite error but the value in product_id column in product_dopingClassification table is value of the primary key id and not the naturalId value


Name and version of the database you are using:
HSQLDB

The generated SQL (show_sql=true):

Hibernate:
insert
into
product
(product_Id, vIn, vOut, name, shortName, veryShortName, spcProductName, spcFolderNumber, spcPosology, spcInternalId, cis, isUnmarket, productDataSempProductionId, maximumDeliveryDuration, pharmacyClassificationRootCode, ranking, pharmacokineticComment, spectrumComment, incompatibilityComment, pharmacodynamicComment, modalityHandlingComment, preclinicalSafetyComment, country_id, productLine_id, pharmacyClassification_id, usefullComplement_id, tasteComplement_id, formComplement_id, composantComplement_id, commonNameGroup_id, form_id, list_id, dosage_id, procedureType_id, id)
values
(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
Hibernate:
insert
into
product_dopingClassification
(isValid, vOut, product_Id, dopingClassification_Id, vIn)
values
(?, ?, ?, ?, ?)


Top
 Profile  
 
 Post subject: Collection mapped to a non primary key fails!
PostPosted: Wed Jan 21, 2009 4:42 pm 
Regular
Regular

Joined: Tue Feb 19, 2008 6:05 pm
Posts: 82
Although I have posted in the wrong location - NHibernate
here is the same problem that I am facing:

http://forum.hibernate.org/viewtopic.php?t=964255


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 22, 2009 4:46 am 
Expert
Expert

Joined: Thu Jan 08, 2009 6:16 am
Posts: 661
Location: Germany
Have you tried to use natural-id?

_________________
-----------------
Need advanced help? http://www.viada.eu


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.