I have the following error,
Hibernate generate the following
Hibernate: insert into public.divisiones (cliente_id, nombre, clienteId, divisionId) values (?, ?, ?, ?)
java.sql.BatchUpdateException: Batch entry 0 public.divisiones (cliente_id, nombre, clienteId, divisionId) values ('1', 'a', '0', '0')But it must be
insert into public.divisiones (cliente_id, nombre, divisionId) values (?, ?, ?)see me class.
Code:
public class DivisionPK implements Serializable {
int clienteId;
int divisionId;
public DivisionPK(int clienteId, int divisionId) {
this.clienteId = clienteId;
this.divisionId = divisionId;
}
public DivisionPK() {
}
public int getClienteId() {
return clienteId;
}
public void setClienteId(int clienteId) {
this.clienteId = clienteId;
}
public int getDivisionId() {
return divisionId;
}
public void setDivisionId(int divisionId) {
this.divisionId = divisionId;
}
public boolean equals(Object object) {
if (object instanceof DivisionPK) {
DivisionPK pk = (DivisionPK)object;
return clienteId == pk.clienteId && divisionId == pk.divisionId;
} else {
return false;
}
}
public int hashCode() {
return clienteId + divisionId ;
}
}
@Entity
@IdClass(DivisionPK.class)
@Table(name="divisiones", schema = "public")
public class Division implements Serializable {
public Division()
{}
public Division(Cliente cliente)
{
this.cliente = cliente;
this.clienteId = cliente.getId();
}
@Id
private int divisionId;
@GeneratedValue
@Column(name="division_id")
public int getDivisionId() {
return divisionId;
}
public void setDivisionId(int divisionId) {
this.divisionId = divisionId;
}
private String nombre;
@Column(name="division_nombre")
public String getNombre() {
return nombre;
}
public void setNombre(String nombre) {
this.nombre = nombre;
}
@Id
@Column(name="cliente_id", insertable=false, updatable=false)
private int clienteId;
@ManyToOne
@JoinColumn(name="cliente_id")
private Cliente cliente;
public Cliente getCliente() {
return cliente;
}
public void setCliente(Cliente cliente) {
this.cliente = cliente;
}
}