• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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
Hi,

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.



Team.hbm.xml

<hibernate-mapping>
<class name="com.test.Team" table="dbo.teams">
<id name="id" column="team_id" >
<generator class="hilo"/>
</id>
<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"/>
</set>
</class>
</hibernate-mapping>





Player.hbm.xml

<hibernate-mapping>
<class name="com.test.Player" table="dbo.players">
<id name="id" column="player_id">
<generator class="hilo"/>
</id>
<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"/>
</class>
</hibernate-mapping>



Any help would be highly appreciated..

Thanks in Advance..

/Shridhar..
 
reply
    Bookmark Topic Watch Topic
  • New Topic