Joined: Wed Apr 20, 2005 6:17 pm Posts: 2
|
Hibernate version: 3.0
Mapping documents:
Snippet:
Team.hbm.xml:
<hibernate-mapping
>
<class
name="Team"
table="Teams"
>
<id
name="id"
column="team_id"
type="long"
unsaved-value="0"
>
<generator class="sequence">
<param name="sequence">team_seq</param>
</generator>
</id>
<bag
name="players"
table="team_players"
lazy="false"
inverse="false"
cascade="all"
>
<key
column="team_id"
>
</key>
<many-to-many
class="Player"
column="player_id"
outer-join="auto"
/>
</bag>
Player.hbm.xml:
<hibernate-mapping
>
<class
name="Player"
table="Players"
>
<bag
name="teams"
table="team_players"
lazy="false"
cascade="none"
inverse="true"
>
<key
column="player_id"
>
</key>
<many-to-many
class="Team"
column="team_id"
outer-join="auto"
/>
</bag>
Code between sessionFactory.openSession() and session.close():
Session session = sessionFactory.openSession();
Team team = new Team();
team.getPlayers().add(new Player());
team.getPlayers().add(new Player());
team.getPlayers().add(new Player());
session.save(team);
session.flush();
session.close();
Session session = sessionFactory.openSession();
Team team2 = new Team();
team2.setPlayers(team.getPlayers());
session.save(team2);
session.flush();
session.close();
Full stack trace of any exception that occurs: None
Name and version of the database you are using:
Oracle 10g
The generated SQL (show_sql=true):
For first team:
insert into teams ...
insert into players ...
nsert into players ...
nsert into players ...
insert into team_players ...
insert into team_players ...
insert into team_players ...
For second team:
insert into teams ...
update players ...
update players ...
update players ...
delete from team_players ... where team_id = ?
insert into team_players ...
insert into team_players ...
insert into team_players ...
-- ? is the old id presumably as only the rows associated
-- with team 2's id exists in team_players
-- Expected entries in team_players for both team 1 and 2
Question: why is hibernate doing the delete for the second team
save?
what should I be using to get the desired results as teams could have
the same players in them, e.g. player plays basketball and baseball.
Debug level Hibernate log excerpt:
|
|