ORA-00932 ... expected TIMESTAMP got BINARY with JPA Native Queries

So I’m using Hibernate 5.6.3 via spring boot with Java 8 and I’m using a JPA repository and using an native update method that does a merge into using Oracle (19C)

Whenever a field that’s declared as a LocalDate in the POJO has a null value this is being passed to Oracle as a binary.

“ORA-00932: inconsistent datatypes: expected TIMESTAMP got BINARY”

Is there a workaround for this?

It’s only happening when the underlying nullable value is a null.

In the database the field is declared as a TIMESTAMP(6)

Hibernate has no way of knowing what the intended parameter type is in case of a native query when you pass a null value, so it tries to bind with the parameter on JDBC with setNull(index, Types.BINARY).

Hibernate 6.0 tries to be a bit smarter and asks the JDBC driver for the type or uses a special NULL type, but in general it is impossible to always infer the correct type. You can pass a TypedParameterValue which contains the type information to use when binding the parameter.

1 Like