I have this Hibernate select query that gives me a ConstraintViolationException.
Method:
public MyParentModelClass findViaChildModelClass(MyChildModelClass childModelClass) {
TypedQuery<MyParentModelClass> query = createQuery("select mpmc from MyParentModelClass mpmc where mpmc.child = :cmc");
query.setParameter("cmc", childModelClass);
return QueryUtil.single(query);
}
Exception:
Caused by: java.sql.SQLIntegrityConstraintViolationException: ORA-01400: cannot insert NULL into (“SCHEMA”.”TABLE_B”.”ID”)
There is no trigger on this query, how can a SELECT query return a ConstraintViolationException?
Here I read that this might be because Hibernate cached a previously created statement but for some reason not yet executed insert statement. Before executing my SELECT statement Hibernate then somehow sees the need to execute the cached INSERT statement. The execution of the INSERT results in a ConstraintViolationException which is why the program doesn’t get the change to execute my SELECT.
I’ve looked everywhere in the code, but I can’t find anything that could try to insert data into TABLE_A. Is there a way to keep hibernate from executing statements in the cache and hence solve the problem?