2

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?.

dantebarba
  • 1,396
  • 1
  • 12
  • 22
  • 1
    When is it null? When you read `PlayerState` back in another session? Also, you are mentioning **two** foreign keys. The first one is `player_state` column. Which is the second one and what do you use it for? – Dragan Bozanovic Jun 24 '15 at 15:34
  • Hi. I solved the issue by deleting the mappedBy entry. Now I have both references, from PlayerState to Player and from Player to PlayerState. – dantebarba Jul 10 '15 at 18:23

0 Answers0