This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Object Relational Mapping and the fly likes Hibernate Bi Directional Problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Hibernate Bi Directional Problem" Watch "Hibernate Bi Directional Problem" New topic
Author

Hibernate Bi Directional Problem

Anna Madhusudhanan Natanagopalan
Greenhorn

Joined: Apr 05, 2004
Posts: 25
Hi ,
I am facing a problem in hibernate bidirectional. I have 2 classes TOrder and LineItem.

What is the problem in the xml file. Is this correct? Or do i need to create the seperate xml file ?

for Bi directional i created the Ora.hbm.xml as

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping SYSTEM "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >
<hibernate-mapping>
<class name="com.bo.TOrder" table="T_ORDER">
<id name ="orderID" type="int">
<column name="ORDERID" not-null="true"/>
<generator class="hilo"/>
</id>
<property column="userName" name="userName" />
<property column="total" name="total" />
<set name="lineItem" inverse="true" lazy="true" cascade="all">
<key column="orderID"/>
<one-to-many class="com.bo.LineItem"/>
</set>
</class>

<class name="com.hibernate.example.bo.LineItem" table="T_LINEITEM">
<id type="int">
<column name="ID" not-null="true"/>
<generator class="hilo"/>
</id>
<property column="itemName" name="itemName" />
<property column="unitPrice" name="unitPrice" />
<property column="discount" name="discount" />
<many-to-one name="order" class="com.bo.TOrder" column="orderID"/>
</class>
</hibernate-mapping>


Thanks in Advance
Anna Madhusudhanan
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
The <key/> element in the <set/> should name the column in the "other" table that holds a reference to "this" table's ID.

I.e. something like:


Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
Oh, wait. That's exactly how you had it. Hmm.
David Harkness
Ranch Hand

Joined: Aug 07, 2003
Posts: 1646
Originally posted by Anna Madhusudhanan Natanagopalan:
I am facing a problem in hibernate bidirectional. I have 2 classes TOrder and LineItem.
Would you care to share it with us? What exactly is the problem? Does Hibernate give you an error when reading the mapping files? Do you get a runtime error when loading objects?
Anna Madhusudhanan Natanagopalan
Greenhorn

Joined: Apr 05, 2004
Posts: 25
I am getting error at run time.
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
Do you have a stack trace to give us? Otherwise it's rather difficult to get an idea of what's happening.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Hibernate Bi Directional Problem
 
Similar Threads
net. sf. hibernate. MappingException: duplicate import -- WTF?
Join using Hibernate
what changes should i made in save method in one-to-many relationships
hibernate migration
One-to-many mapping and composite key