Insert foreign key hibernate

0

I have four entities (selection, start, bet and bettor) where within the Bet class I have the IDs of a bet and a bettor. When I try to insert a bet by loading the game and the bettor into it, it gives me the following error:

  

org.hibernate.id.IdentifierGenerationException: ids for this class must be manually assigned before calling save ():

Bet Class

public class Aposta implements Serializable {

private static final long serialVersionUID = 1L;
@Id
@Basic(optional = false)
@NotNull
@Column(name = "idAposta")
private Integer idAposta;
@Size(max = 3)
@Column(name = "Palpite")
private String palpite;
@Size(max = 1)
@Column(name = "Status")
private String status;
@JoinColumn(name = "Apostador_idApostador", referencedColumnName = "idApostador")
@ManyToOne(optional = false, cascade = CascadeType.ALL) 
private Apostador apostadoridApostador;
@JoinColumn(name = "Partida_idPartida", referencedColumnName = "idPartida")
@ManyToOne(optional = false, cascade = CascadeType.ALL)
private Partida partidaidPartida;

I think it's some mapping now I do not know which one. I found that I needed to add the cascade parameter inside @ManyToOne but it still did not roll.

    
asked by anonymous 20.04.2018 / 15:32

1 answer

0

According to this response, you need to put the signature to auto increment the IDs of your Entity . Use @GeneratedValue(strategy=GenerationType.IDENTITY) in fields that are @Id that will already do this automatically.

    
27.04.2018 / 13:16