I have a Java program which uses Hibernate to interact with a MySQL DB with two tables, User and Status.
As I had only User Table, everything worked fine, but now I added the Status table and now I get the following exception when inserting testdata, but now for both of the tables though I didn't change anything in the User table:
Could not update entity of typ User
Aug 12, 2016 11:37:01 AM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
WARN: SQL Error: 1364, SQLState: HY000
Aug 12, 2016 11:37:01 AM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
ERROR: Field 'status_statusId' doesn't have a default value
Aug 12, 2016 11:37:01 AM org.hibernate.engine.jdbc.batch.internal.AbstractBatchImpl release
INFO: HHH000010: On release of batch it still contained JDBC statements
Could not update entity of typ Status
Aug 12, 2016 11:37:01 AM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
WARN: SQL Error: 1364, SQLState: HY000
Aug 12, 2016 11:37:01 AM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
ERROR: Field 'user_email' doesn't have a default value
Aug 12, 2016 11:37:01 AM org.hibernate.engine.jdbc.batch.internal.AbstractBatchImpl release
INFO: HHH000010: On release of batch it still contained JDBC statements
Here are excerpts of my entity classes with the annotations and the variables:
User:
@Entity
@Table(name = "user")
public class User implements Serializable {
@PrePersist
void preInsert() {
email = "test@testmail.com";
}
@Id
@Column(name = "user_email")
private String email;
Status:
@Entity
@Table(name = "status")
public class Status implements Serializable {
@PrePersist
void preInsert() {
statusId = "A01A001";
}
@Id
@Column(name = "status_statusId")
private String statusId;
Looks like some kind of NOT NULL issue to me, but I used the @PrePersist annotation to ensure a default value in both entities.
I searched for some solutions bot none of them worked, like this one: mysql error 1364 Field doesn't have a default values
They suggest to change the mysql settings and remove STRICT_TRANS_TABLES in my.cnf. But I couldn't find this file so I tried the phpmyadmin solution. They say you should edit the sql mode variable there and remove the STRICT_TRANS_TABLES value, but when I try to edit this variable it has no value:
Does someone know another solution for this? Would be grateful for every helpful answer.