Hibernate is throwing the following exception:
Caused by: java.sql.SQLException: Field 'catVerb_id' doesn't have a default value
People say that the problem is with my PKs that haven't the AUTO_INCREMENT statement, however you can see that I've done this in my database and the issue continues. So, I brought my classes and my database implementations.
I think my problem is with the testing class... Somebody could show me how do I test this?
(Yes, some words are in Portuguese, but you can understand).
CategoriaVerbete
@Entity
@Table(name="verbete_categoria")
public class CategoriaVerbete implements Serializable{
private long id;
private String nome;
private String descricao;
private int serie;
private Set<Verbete> verbetes = new HashSet<Verbete>();
private Set<SignificadosVerbete> significados = new HashSet<SignificadosVerbete>();
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name="catVerb_id")
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
...
@OneToMany(cascade = {CascadeType.ALL})
@JoinColumn(name="catVerb_id", nullable = true)
public Set<Verbete> getVerbetes() {
return verbetes;
}
public void setVerbetes(Set<Verbete> verbetes) {
this.verbetes = verbetes;
}
@OneToMany(cascade = {CascadeType.ALL})
@JoinColumn(name="catVerb_id", nullable = true)
public Set<SignificadosVerbete> getSignificados() {
return significados;
}
public void setSignificados(Set<SignificadosVerbete> significados) {
this.significados = significados;
}
}
Verbete
@Entity
@Table(name="verbete")
public class Verbete implements Serializable{
...
@ManyToOne
@JoinColumn(name="catVerb_id", insertable = false, updatable = false)
public CategoriaVerbete getCategoria() {
return categoria;
}
public void setCategoria(CategoriaVerbete categoria) {
this.categoria = categoria;
}
...
}
SignificadosVerbete
@Entity
@Table(name="verbete_significados")
public class SignificadosVerbete {
...
@ManyToOne(cascade = CascadeType.ALL)
@JoinColumn(name="catVerb_id", insertable = false, updatable = false)
public CategoriaVerbete getCategoria() {
return categoria;
}
public void setCategoria(CategoriaVerbete categoria) {
this.categoria = categoria;
}
...
}
In the database...
CREATE TABLE verbete_categoria (
catVerb_id INT PRIMARY KEY NOT NULL AUTO_INCREMENT,
catVerb_nome VARCHAR(100) UNIQUE,
catVerb_descricao MEDIUMTEXT,
catVerb_serie INT NOT NULL
);
Any help will be appreciated, thank you.
UPDATE - PROBLEM SOLVED
Well, I was expecting a triumphant soundtrack, but it's ok...
I just followed what this link says:
I read that what is in that link isn't recommended by the Hibernate documentation, but I tried to follow the recomendations and passed one week treating errors. So, I hope this helps other people.
And thanks for all the answers.