• 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 ...
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

One to Many && Many to One mapping

Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I am trying "<many-to-one name>" && "<one-to-many>".[Ref : ]http://www.javaranch.com]

Team --> Player..

Data is getting inserted, but key colums are "team_id" column in the players table is NULL.
I think team_id's will be automatically inserted by Hibernat{using <id>} and both have to be same to maintain the relation..

Hence, when i try to fetch the data;

i.e. First I fetch Teams and from Teams i am trying to get-Players(). Players Set is not having any values because there is no mapping between Team <--> Player..

Can anyone tell me what am i missing.

*] Is there anything wrong in xmls.
*] DB mapping need to be changed. Currently i have team_id from Teams && player_id from PLayers are PK's.


<class name="com.test.Team" table="dbo.teams">
<id name="id" column="team_id" >
<generator class="hilo"/>
<property name="name" column="team_name" />
<property name="city" column="city" />
<set name="players" cascade="all" inverse="true" lazy="true">
<key column="team_id"/>
<one-to-many class="com.test.Player"/>


<class name="com.test.Player" table="dbo.players">
<id name="id" column="player_id">
<generator class="hilo"/>
<property name="firstName" column="first_name" />
<property name="lastName" column="last_name" />
<property name="draftDate" column="draft_date" />
<property name="annualSalary" column="salary" />
<property name="jerseyNumber" column="jersey_number" />
<many-to-one name="team" class="com.test.Team" column="team_id"/>

Any help would be highly appreciated..

Thanks in Advance..

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
    Bookmark Topic Watch Topic
  • New Topic