尝试在两个具有两个外键的实体之间创建OneToOne关系时遇到问题。
public class Player {
@JoinColumn(name = "player_state")
@OneToOne(fetch = FetchType.EAGER ,cascade = {CascadeType.PERSIST, CascadeType.MERGE})
private PlayerState playerState;
}
public class PlayerState {
@OneToOne(mappedBy="playerState")
private Player player;
}
当我表演时:
Player player = new Player();
PlayerState state = new PlayerState();
state.setPlayer(player)
Player.setPlayerState(state);
DAO.persist(player);
播放器是持久的,在player_state上引用了PlayerState。 PlayerState保持不变。
从PlayerState到Player的引用为空。
我无法将PlayerState的引用作为引用播放器的ID。
任何想法?。