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?