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

please help ! Two collections found for the same object error (hibernate)

 
jay vas
Ranch Hand
Posts: 407
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi I have the following scenario.

I have a HashSet<Player> inside of my Team object.

A new season comes around, so I need to replace the old set with new players.

Im doing the following.

1) delete each player
2) flush the session
3) insert the new players...

This is followed by a "two collections found" exception thrown by hibernate. Please let me know the general way of replacing a collection in an application which is a typical CRUD "form editor" style GUI to a hibernate backend.

Thanks so much ....

J
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you post your mapping for this Collection. and also the Code for both classes to see how you implement your "removeFromCollection" approach. Do you have it bi-directional where when you remove it from the Collection, you also need to null out the object on the other side, meaning

player.team = null;

Mark
 
jay vas
Ranch Hand
Posts: 407
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
so wait a second... It seems like this is counterintuitive. If you simply set something as equal to null, that is to say there simply is no team. That is not the case - it is more natural to take the collection of players from a team object and change its contents. right?
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by jay vas:
so wait a second... It seems like this is counterintuitive. If you simply set something as equal to null, that is to say there simply is no team. That is not the case - it is more natural to take the collection of players from a team object and change its contents. right?


Not if it is a bi-directional relationship in your mapping and in your object model.

If you have a Team.players collection, and in Player you have a Team reference and you only remove the player from the Collection to a Team, then it is like the Team got rid of the player, without letting the Player know that they are no longer part of the Team. So if you call player.getTeam, you are getting a Team object back.

That is just plain mean. A Team firing/trading a player without letting the player know.

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