Hey guys, I'm using hibernate on my project, and I've got a parent class & child class in a onetoone relationship, with the parent having a cascade=ALL to the child. When I'm persisting the parent, I see that the db is queried for the child (to see if it already exists, which it doesn't, the table is empty), and right after hibernate tries to insert the parent before the child, thus giving a FK constraint error. Do you know anything about this?
Code:
@Entity
@Table(name = "LANOMAL")
public class LAnomal extends Throwable implements java.io.Serializable {
[...]
@OneToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
@PrimaryKeyJoinColumn
public LStacktrace getStacktraceString() {
return stacktraceString;
}
}
@Entity
@Table(name = "LSTACKTRACE")
public class LStacktrace implements java.io.Serializable {
[...]
@OneToOne(fetch = FetchType.LAZY, mappedBy = LAnomal.PROP_LSTACKTRACE)
public LAnomal getException() {
return this.exception;
}
}
Quote:
INFO: Hibernate: select lanomal0_.DTCREAT as DTCREAT29_1_, lanomal0_.ADAMID as ADAMID29_1_, [...] from LANOMAL lanomal0_ left outer join LSTACKTRACE lstacktrac1_ on lanomal0_.DTCREAT=lstacktrac1_.DTCREAT where lanomal0_.DTCREAT=?
INFO: Hibernate: select lstacktrac0_.DTCREAT as DTCREAT49_0_, lstacktrac0_.CKEEP as CKEEP49_0_, [...] from LSTACKTRACE lstacktrac0_ where lstacktrac0_.DTCREAT=?
INFO: Hibernate: insert into LANOMAL (ADAMID, ANOMAL, CKEEP, DARCH, NOMCLASSE, CORELID, SLEUTEL, MSGID, METHODE, DTWIJZ, module, PACKAGE, RECRC, CTRAIT, USERID, DTCREAT) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
WARNING: 14578 [SimpleAsyncTaskExecutor-33] WARN org.hibernate.util.JDBCExceptionReporter - SQL Error: -530, SQLState: 23503
WARNING: 14578 [SimpleAsyncTaskExecutor-33] ERROR org.hibernate.util.JDBCExceptionReporter - DB2 SQL error: SQLCODE: -530, SQLSTATE: 23503, SQLERRMC: EVAADM.LANOMAL.FKLANOMAL
Any help would be greatly appreciated!