Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hibernate Bi Directional Problem

 
Anna Madhusudhanan Natanagopalan
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh, wait. That's exactly how you had it. Hmm.
 
David Harkness
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am getting error at run time.
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you have a stack trace to give us? Otherwise it's rather difficult to get an idea of what's happening.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic