0

あるエンティティをその親から削除して別の親に追加するにはどうすればよいですか?これが私のコードです。TeamがありList<Player>Playerその親との関連付けがあります。

Player player = entityManager.find(Player.class, playerKey);
Team team1 = player.getTeam();
team1.getPlayers().remove(player); // this action will cascade the deletion of player;
entityManager.merge(team1);

Team team2 = entityManager.find(Team.class, team2Key);
team2.getPlayers().add(player);
entityManager.merge(team2);

これは私がやりたいことですが、失敗に終わります。他のチームで使用できると思いentityManager.detach(player)ましたが、GAE jar(?)ではこの方法は利用できません。

4

1 に答える 1

1

You mean this is a GAE "owned" relation? In which case you likely can't change the "owner" since GAE will have put it into the Key of the Player.

If instead you make the relation as "unowned" (like all relations for all other datastores) you can obviously reparent it. You need to be using GAE/J JPA plugin v2.x for this.

And yes GAE/J JPA does support JPA2, if you're using the GAE/J JPA plugin v2.x (with DataNucleus 3.x)

于 2012-10-11T15:31:21.647 に答える