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..