Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hibernate 3.0 many-to-one relationships

 
Nithya Priya
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have 2 tables Team and Player, the primary key of Team is teamid that is auto incremented which is the foreign key for the table Player, I used the <one-to-many relationship in my hbm files, When I save the object, Im not getting any error, but the team id is not getting inserted in the Player table. Can anyone please help.

Team.hbm.xml

<hibernate-mapping>
<class name="com.test.Team" table="team">
<id name="teamid" column="team_id" >
<generator class="increment"/>
</id>
<property name="name" column="team_name" />
<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="player">
<id name="playerid" column="player_id">
<generator class="increment"/>
</id>
<property name="firstName" column="first_name" />
<property name="lastName" column="last_name" />
<many-to-one name="team" class="com.test.Team" column="pl_team_id"/>
</class>
</hibernate-mapping>

Thanks in advance.
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try putting the inverse="true" part in the Players side instead of in the Team side.

Mark
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic