Insert foreign key Hibernate

Asked

Viewed 162 times

0

I have four entities (selection, match, 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 clicking on the match and the player, it generates the following error:

org.hibernate.id.Identifiergenerationexception: ids for this class must be Manually Assigned before Calling save():

Class Bet

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 believe it’s some kind of mapping now I don’t know which one. I searched that I needed to add the Cascade parameter inside @Manytoone but it still didn’t roll.

1 answer

0

According to this answer, you need to put the signature to auto increment the Ids of your Entity. Utilize @GeneratedValue(strategy=GenerationType.IDENTITY) in the fields that are @Id that will already make this automatic.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.