I can't understand why Hibernate is trying to set this field as a VARBINARY when it is null.
The Java data type is BigDecimal The Oracle data type is Float
It is being set like this:
entityManager.createNamedQuery("blah").setParameter("target_field", object.sourceValue)
again - sourceValue is a BigDecimal, and when i debug it the value is null.
when it tries to execute this update, I get oracle error:
ORA-00932: inconsistent datatypes: expected NUMBER got BINARY
this is what shows up for this property in the console log:
o.h.type.descriptor.sql.BasicBinder : binding parameter [8] as [VARBINARY] - [null]
IF I do this silly hack in Java before I execute the update:
if (object.sourceValue == null) object.sourceValue = new java.math.BigDecimal(0);
Then it runs fine. So the cause of this error is definitely not anything else than hibernate doing something wrong when the field is null.
How do I fix this so I can set the field to null without hibernate mishandling it?
In the DB, the field is nullable.
It looks the issue has not been resolved yet even with newer version of hibernate 5.2.17.Final
with JPA.
The null parameter is being sent as VARBINARY
which causes the error
ERROR [org.hibernate.engine.jdbc.spi.SqlExceptionHelper] - ERROR: cannot cast type bytea to bigint
One workaround to this is to use the org.hibernate.Query that is wrapped into the org.hibernate.ejb.QueryImpl this way:
QueryImpl q = (QueryImpl) this.entityManager.createNamedQuery("myNamed.query");
q.getHibernateQuery().setParameter("name", value, org.hibernate.Hibernate.BIG_DECIMAL);
q.getResultList();
When value
is null, hibernate still can know which type the parameter must be, so it doesn't translate the null to a binary value.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With