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: 2 different many-to-one with comp. id with one common column
PostPosted: Wed May 27, 2009 6:22 am 
Newbie

Joined: Wed May 27, 2009 6:10 am
Posts: 4
We have a problem mapping on a legacy database

We this table, ImpVerifi, that 3 many-to-one reletionship with 3 different tables, two of them with composite id

here our mapping:

Code:
<?xml version="1.0" ?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
      "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping default-cascade='none' default-access='property' default-lazy='true' auto-import='true'>
   <class polymorphism='implicit' dynamic-update='false' name='ImpVerifi'
         select-before-update='false' mutable='true' optimistic-lock='version' dynamic-insert='false'  table='imp_verifi'>
      <id name='impVerifiId' type='int'>
         <column name='imp_verifi_id'/>
         <generator class='increment'/>
      </id>
      <many-to-one update='false' fetch='select' unique='false' embed-xml='true' name='imp' not-found='exception'
                class='Imp' optimistic-lock='true' insert='false'>
         <column not-null='true' name='id_imp' length='16'/>
      </many-to-one>
      <many-to-one update='true' fetch='select' unique='false' embed-xml='true' name='impGenCal' not-found='exception' class='ImpGenCal' optimistic-lock='true' insert='true'>
         <column not-null='true' name='id_imp_gen_cal' length='16'/>
         <column not-null='true' name='id_imp' length='16'/>
      </many-to-one>
      <many-to-one update='true' fetch='select' unique='false' embed-xml='true' name='impBruc' not-found='exception' class='ImpBruc' optimistic-lock='true' insert='true'>
         <column name='id_imp_bruc' length='16'></column>
         <column name='id_imp' length='16' ></column>
      </many-to-one>
      //some properties
   </class>
</hibernate-mapping>


so the 3 relationship have the same column in common "id_imp"
that's is a primary key of table imp

with this mapping we get this error:
2009-05-27 11:59:43,312 [main] ERROR mortbay.log - Nested in org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'messageSource': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Invocation of init method failed; nested exception is org.hibernate.MappingException: Repeated column in mapping for entity: com.fdlservizi.sse.client.domain.ImpVerifi column: id_imp (should be mapped with insert="false" update="false"):
org.hibernate.MappingException: Repeated column in mapping for entity: com.fdlservizi.sse.client.domain.ImpVerifi column: id_imp (should be mapped with insert="false" update="false")

but if we put insert and update false, for example, on the impBruc many-to-one, this column (impBruc) is not updated/inserted in the db... so is not what we want
How we can do that?


Last edited by valex on Thu Jun 11, 2009 4:30 am, edited 2 times in total.

Top
 Profile  
 
 Post subject: Re: 2 different many-to-one with comp. id with one common column
PostPosted: Thu May 28, 2009 9:17 am 
Newbie

Joined: Wed May 27, 2009 6:10 am
Posts: 4
I tried various way, the result is that only this mapping does not cause compile errors (even if it doesn't save the value impBruc):

Code:
<many-to-one update='true' fetch='select' unique='false' embed-xml='true' name='impGenCal' not-found='exception' class='ImpGenCal' optimistic-lock='true' insert='true'>
         <column not-null='true' name='id_imp_gen_cal' length='16'/>
         <column not-null='true' name='id_imp' length='16'/>
      </many-to-one>
<many-to-one update='false' fetch='select' unique='false' embed-xml='true' name='impBruc' not-found='exception' class='ImpBruc' optimistic-lock='true' insert='false'>
         <column name='id_imp_bruc' length='16'></column>
         <column name='id_imp' length='16' ></column>
      </many-to-one>


but I don't understand the difference between the class mapping...

Code:
<?xml version="1.0" ?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
      "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping default-cascade='none' default-access='property' default-lazy='true' auto-import='true'>
   <class polymorphism='implicit' dynamic-update='false' name='ImpBruc'
         select-before-update='false' mutable='true' optimistic-lock='version' dynamic-insert='false'
         table='imp_bruc'>
      <composite-id name='id' class='ImpBrucId' unsaved-value='undefined' mapped='false'>
         <key-property name='id' type='string'>
            <column name='id' length='16'></column>
         </key-property>
         <key-many-to-one column="id_imp" name='idImp' class="Imp" />
      </composite-id>            
      <many-to-one update='false' fetch='select' unique='false' embed-xml='true' name='idImpGenCal' not-found='exception'
                class='ImpGenCal' optimistic-lock='true' insert='false'>
         <column not-null='true' name='id_imp_gen_cal' length='16'></column>
         <column not-null='true' name='id_imp' length='16'></column>
      </many-to-one>
      <property >
         ...
      </property>
      ...
      <set sort='unsorted' embed-xml='true' inverse='true' name='impVerifis' mutable='true' optimistic-lock='true'>
         <key on-delete='noaction'>
            <column name='id_imp_bruc' length='16'></column>
            <column not-null='true' name='id_imp' length='16'></column>
         </key>
         <one-to-many embed-xml='true' not-found='exception' class='ImpVerifi'></one-to-many>
      </set>
   </class>
</hibernate-mapping>

<?xml version="1.0" ?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
      "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping default-cascade='none' default-access='property' default-lazy='true' auto-import='true'>
   <class polymorphism='implicit' dynamic-update='false' name='ImpGenCal'
         select-before-update='false' mutable='true' optimistic-lock='version' dynamic-insert='false'
         table='imp_gen_cal'>
      <composite-id name='id' class='ImpGenCalId' unsaved-value='undefined' mapped='false'>
         <key-property name='id' type='string'>
            <column name='id' length='16'></column>
         </key-property>
         <key-many-to-one column="id_imp" name='idImp' class="Imp" />         
      </composite-id>            
      <property>
         ...
      </property>      
      ...
      <set sort='unsorted' embed-xml='true' inverse='true' name='impVerifis' mutable='true' optimistic-lock='true'>
         <key on-delete='noaction'>
            <column not-null='true' name='id_imp_gen_cal' length='16'></column>
            <column not-null='true' name='id_imp' length='16'></column>
         </key>
         <one-to-many embed-xml='true' not-found='exception' class='com.fdlservizi.sse.client.domain.ImpVerifi'></one-to-many>
      </set>
      <set sort='unsorted' embed-xml='true' inverse='true' name='impBrucs' mutable='true' optimistic-lock='true'>
         <key on-delete='noaction'>
            <column not-null='true' name='id_imp_gen_cal' length='16'></column>
            <column not-null='true' name='id_imp' length='16'></column>
         </key>
         <one-to-many embed-xml='true' not-found='exception' class='com.fdlservizi.sse.client.domain.ImpBruc'></one-to-many>
      </set>
   </class>
</hibernate-mapping>


Why the second configuration works and the first doesn't?
To explain the relation between the classes i post the following UML schema.

Image


Top
 Profile  
 
 Post subject: Re: 2 different many-to-one with comp. id with one common column
PostPosted: Thu Jun 11, 2009 4:50 am 
Newbie

Joined: Wed May 27, 2009 6:10 am
Posts: 4
Any news? Nobody can help me?
I think i find another Hibernate bug! :-(


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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.