I have a field defined in the database as (mySQL) :
Code:
invoiceProductParent int(10) unsigned not null default 0
I can not have any null value since the main site is in PHP5, while what I am trying to code is in Java with Hibernate.
The object in the class is:
Code:
@ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY, optional = true)
@JoinColumn(name = "invoiceProductParent")
private InvoiceProduct invoiceProductParent;
I am trying to insert a value of "0" if there is no invoiceProductParent present (instead of the value null), and the id of the object referenced if there is one.
Even though in the database there is a default of 0, it seems to ignore it when it tries to insert the value. If I do not specify any value, I get the following error message:
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Column 'invoiceProductParent' cannot be null
What can I do to make the above work?
Thanks.