IntelliJ Java IDE
The moose likes Object Relational Mapping and the fly likes Hibernate 3.0 many-to-one relationships Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Object Relational Mapping
Reply Bookmark "Hibernate 3.0 many-to-one relationships" Watch "Hibernate 3.0 many-to-one relationships" New topic
Author

Hibernate 3.0 many-to-one relationships

Nithya Priya
Greenhorn

Joined: Jul 28, 2006
Posts: 1
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

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
 
jQuery in Action, 2nd edition
 
subject: Hibernate 3.0 many-to-one relationships
 
Threads others viewed
Hibernate: Path expected for Join! exception for inner join
One to Many && Many to One mapping
could not initialize a collection+ [Microsoft][ODBC SQL Server Driver]Invalid Descrip
One to many Relation
Mapping Exception
developer file tools