P
pek
OK, here is what I have:
Class Game with :
@OneToMany
List getTeams()
@OneToOne
CardStack centerStack()
Class Team
@OneToMany
List getPlayers()
Class Player
@OneToOne
CardStack getHandStack()
Class CardStack
@OneToMany
List getCards()
Every list is an ArrayList. The problem is that I has a Stateful Bean
GameManager that has a persisted game reference.
When all players tell to the game that they are ready to play through
the setPlayerReady(boolean state) of GameManager, then the method
startGame() automatically is called. startGame() adds 108 cards in the
centerStack and then from centerStack it gives each player 11 cards by
removing them from the centerStack (I do more things with it thats why
I don't give them right away to players hand). This is done by using
this method:
for (Team aTeam:game.getTeams()) {
for (Player aPlayer:aTeam.getPlayers()) {
aPlayer.getHandStack().getCards().add(game.getCenterStack().getCards().remove(0));
}
}
This correctly adds 11 cards to player's hand. But the funny part is
that it also adds 11 identical references of the player in the team!
After doing this, I refresh the game through EntityManager manager;
manager.refresh(game) and call
game.getTeams().get(0).getPlayers().size() = 11. All players are the
same one. The database has everything correct, 1 player for each team
and 11 cards for each player. I don't get it..I tried doing every
thing.. Flushing before adding cards, flushing before removing,
refreshing, merging..Everything.. And the wierd part is that every
change makes other malfunctions. Some times I get a duplicate key
violation when I try to remove one card from center stack and add it
to players hand all at once (like above) and to avoid this I have to
do:
Card aCard = game.getCenterStack().getCards().remove(0);
manager.flush();
aPlayer.getHandStack().getCards().add(aCard);
and that works but has other problems... I can't find any good source
for working with collections..
Any help..?
Thanks in advance.
Class Game with :
@OneToMany
List getTeams()
@OneToOne
CardStack centerStack()
Class Team
@OneToMany
List getPlayers()
Class Player
@OneToOne
CardStack getHandStack()
Class CardStack
@OneToMany
List getCards()
Every list is an ArrayList. The problem is that I has a Stateful Bean
GameManager that has a persisted game reference.
When all players tell to the game that they are ready to play through
the setPlayerReady(boolean state) of GameManager, then the method
startGame() automatically is called. startGame() adds 108 cards in the
centerStack and then from centerStack it gives each player 11 cards by
removing them from the centerStack (I do more things with it thats why
I don't give them right away to players hand). This is done by using
this method:
for (Team aTeam:game.getTeams()) {
for (Player aPlayer:aTeam.getPlayers()) {
aPlayer.getHandStack().getCards().add(game.getCenterStack().getCards().remove(0));
}
}
This correctly adds 11 cards to player's hand. But the funny part is
that it also adds 11 identical references of the player in the team!
After doing this, I refresh the game through EntityManager manager;
manager.refresh(game) and call
game.getTeams().get(0).getPlayers().size() = 11. All players are the
same one. The database has everything correct, 1 player for each team
and 11 cards for each player. I don't get it..I tried doing every
thing.. Flushing before adding cards, flushing before removing,
refreshing, merging..Everything.. And the wierd part is that every
change makes other malfunctions. Some times I get a duplicate key
violation when I try to remove one card from center stack and add it
to players hand all at once (like above) and to avoid this I have to
do:
Card aCard = game.getCenterStack().getCards().remove(0);
manager.flush();
aPlayer.getHandStack().getCards().add(aCard);
and that works but has other problems... I can't find any good source
for working with collections..
Any help..?
Thanks in advance.