Author
Hibernate 3.0 many-to-one relationships
Nithya Priya
Greenhorn
Joined: Jul 28, 2006
Posts: 1
posted Jul 28, 2006 05:00:00
0
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
Joined: Feb 05, 2001
Posts: 16622
posted Jul 28, 2006 10:55:00
0
Try putting the inverse="true" part in the Players side instead of in the Team side. Mark
Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
subject: Hibernate 3.0 many-to-one relationships