PostgreSQL JDBC Null String taken as a bytea

后端 未结 9 586
后悔当初
后悔当初 2020-12-10 02:59

If entity.getHistory() is null following code snippet:

(getEntityManager() returns spring injected EntityManager, database field history type is: text or varchar2(20

相关标签:
9条回答
  • 2020-12-10 03:22

    The JDBC setNull with sql type parameter is fallback for legacy JDBC drivers that do not pass the JDBC Driver Test Suite.

    One can guard against null errors within the query as follows:

    SELECT a FROM Author a WHERE :lastName IS NULL OR LOWER(a.lastName) = :lastName

    This should work in Postgresql after the fix of this issue.

    0 讨论(0)
  • 2020-12-10 03:28

    Most of above answers are meaningful and helped me to narrow down issue.

    I fixed issue for nulls like this:

    setParameter(8, getDate(), TemporalType.DATE);
    
    0 讨论(0)
  • 2020-12-10 03:31

    There's a simple fix: when you're building the query string, if a parameter is going to be null -- use "null" instead of "?".

    As @araqnid says, Hibernate is incorrectly casting null values into type bytea because it doesn't know any better.

    0 讨论(0)
提交回复
热议问题