Win a copy of Zero to AI - A non-technical, hype-free guide to prospering in the AI era this week in the Artificial Intelligence and Machine Learning forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

Please suggest on this Mapping

 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there something wrong in this mapping. The parent is saved but Child failed to Save.

This is a simple one-to-many mapping of Dept(one) and Emp (Many) with composite PK and no FK.
I am using composite PK class. Do we really need the existence of FK for mapping ?

dept.hbm.xml
--------------------------------------------------------------------------------------

<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping package="hello">
<class name="Dept" table="DEPT">

<composite-id name="key" class="DeptKey">
<key-property name="empno" type="string"/>
<key-property name="deptno" type="string"/>
</composite-id>

<property name="deptname" type="string"/>

<set name="emp" table="emp" inverse="true" cascade="all" lazy="false">
<key>
<column name="EMPNO" />
<column name="DEPTNO" />
</key>
<one-to-many class="Emp" />
</set>

</class>
</hibernate-mapping>


emp.hbm.xml
---------------------------------------------------------------

<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping package="hello">
<class name="Emp" table="EMP">

<composite-id name="key" class="EmpKey">
<key-property name="empno" type="string"/>
<key-property name="deptno" type="string"/>
</composite-id>

<property name="sal" type="string"/>
<property name="loc" type="string"/>

<many-to-one name="dept" insert="false" update="false" cascade="save-update" class="Dept"/>
<column name ="empno"/>
<column name="deptno"/>
</many-to-one>

</class>
</hibernate-mapping>


In many-to-one mapping I had to set insert and update to false as Hibernate is giving following error -

*** Repeated column in mapping for entity: EMP column: EMPNO (should be mapped with insert="false" update="false")


Persistence class and Client is here -
Complete Code
 
Ranch Hand
Posts: 278
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Its look okay to me. May be you need to look into the client program, how you are persisting it.
 
Ranch Hand
Posts: 662
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can't we use something like this,

[ August 10, 2006: Message edited by: Arun Kumarr ]
 
And tomorrow is the circus! We can go to the circus! I love the circus! We can take this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic