Short version, using a native query with setParameter passing a null Long object, the framework seems to be mapping this null value to a VARBINARY type instead of a number, causing an oracle error... long version below
I have some code (JPA w/hibernate3.3.2) that generates a native query that includes something akin to:
... LEFT OUTER JOIN table2 tb2 ON tb2.id = :table2ID ...
where (tb2.id is Number(12))
and Java code:
Code:
public List<ResultVO> exec(Long tb2ID, ...)
return this.em
.createNativeQuery(MyClass.SQL, ResultVO.class)
.setParameter("table2ID", tb2ID)
.getResultList();
(Its a relatively long query, and private to a financial company, so sorry for the obfuscation...)
In the logs I get:
ORA-00932: inconsistent datatypes: expected NUMBER got BINARY
When I enabled jdbc logging in weblogic, I noticed that it was doing this behind the scenes:
<[weblogic.jdbc.wrapper.PreparedStatement_oracle_jdbc_driver_OraclePreparedStatementWrapper@6f] setNull(1, -3)>
Which explains the issue as Types.VARBINARY is -3.
Not sure how to fix this short of changing the query to conditionally include "null" or ":param" in the SQL string, and then only setting the parameter if the Long is not null, which I would prefer not to do...
Any thoughts? Thanks.