This week's book giveaway is in the Java in General forum.
We're giving away four copies of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 and have ishori Sharan & Adam L Davis on-line!
See this thread for details.
Win a copy of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 this week in the Java in General 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Hibernate Bi Directional Problem

 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 11962
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oh, wait. That's exactly how you had it. Hmm.
 
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am getting error at run time.
 
Lasse Koskela
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
WHAT is your favorite color? Blue, no yellow, ahhhhhhh! Tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic