Hibernate: Bidirectional @OneToOne relationship

138 views Asked by At

I'm having issues when trying to create a OneToOne relationship between two entities with two Foreign Keys.

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;
}

When I perform:

Player player = new Player();
PlayerState state = new PlayerState();
state.setPlayer(player)
Player.setPlayerState(state);

DAO.persist(player);

Player is persisted OK, with a reference to PlayerState on player_state. PlayerState is persisted OK.

The reference from PlayerState to Player is null.

I can't get the reference of PlayerState to be the ID of the referenced player.

Any ideas?.

0

There are 0 answers