@JoinColumn( name="idAssociado" )
private Associado titular;
My problem is that when I try to persist a fully configured Associado (with a Filiation that has a Dependente which, in turn, has a reference to the parent Associado) the inserts generated by Hibernate seem to be out of order. I mean, first Hibernate tries to insert the Dependente entity, which has a reference to the primary key of Associado. But, at this point, Associado was not inserted yet. So, I'm getting this error:
Caused by: java.sql.BatchUpdateException: Column 'idAssociado' cannot be null
And this is the SQL generated by hibernate:
insert into DEPENDENTES (nome, nascimento, idParentesco, idAssociado, beneficiarioPeculio, dependentePlanoSaude, id) values ('Nome Qualquer', '', 3, '', 'false', 'false', 6900)
Right after the em.persist (I'm using Hibernate JPA) I stop the thread in the debugger and I can see that All the objects got an ID assigned. However, during the commit I'm getting this error.
Does anyone have any hint about this?
Thanks in advance!