[hibernate-dev] many-to-one association no persists

Max Rydahl Andersen max.andersen at jboss.com
Sun Sep 10 12:31:30 EDT 2006


http://forum.hibernate.org

> Hello,
>
> I am having a problem to insert or update the Exam object, as follow:
>
> Exam.hbm.xml
> [code]
>
> <!DOCTYPE hibernate-mapping PUBLIC
>      "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
>      "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >
>
>  <hibernate-mapping>
>  <!--
>      Created by the Middlegen Hibernate plugin 2.2
>
>      <a href="http://boss.bekk.no/boss/middlegen/" target="_blank"
> rel="nofollow">http://boss.bekk.no/boss/middlegen/</a>
>      <a href="http://www.hibernate.org/" target="_blank"
> rel="nofollow">http://www.hibernate.org/</a>
>  -->
>
>  <class
>      name="Exam"
>      table="exam"
>  >
>
>      <composite-id name="comp_id" class="ExamPK">
>          <key-property
>              name="cdUnit"
>              column="cd_unit"
>              type="java.lang.Integer"
>              length="4"
>          />
>          <key-property
>              name="cdExam"
>              column="cd_exam"
>              type="java.lang.Integer"
>              length="4"
>          />
>      </composite-id>
>
>      <many-to-one
>          name="pacient"
>          class="Pacient"
>          not-null="true"
>          update="false"
>  	insert="false"
>      >
>          <column name="cd_pacient" />
>          <column name="cd_unit" />
>      </many-to-one>
>
>  </class>
>  </hibernate-mapping>
>
>  [/code]
>
> The problem is that the association with pacient is not pesisting in
> the database, due to update="false" insert="false" configuration.
> But without this configuration, occour a mapping error:
> org.hibernate.MappingException: Repeated column in mapping for entity:
> Exam column: cd_unit (should be mapped with insert="false"  
> update="false").
>
> The exam table have as PK (cd_exam and cd_unit) e the pacient table PK
> (cd_pacient and cd_unit).
> But I need to persist the reference to pacient when I am insert or
> update the exam objet in the database.
>
> Please could anyone help me?
>
> Thanks,
> Rufino.



-- 
--
Max Rydahl Andersen
callto://max.rydahl.andersen

Hibernate
max at hibernate.org
http://hibernate.org

JBoss a division of Red Hat
max.andersen at jboss.com




More information about the hibernate-dev mailing list