With table:
CREATE TABLE person ( id integer, name varchar(255) );
The following fails when using JPA 2.0 EntityManager :
String sql = "INSERT INTO person (id, amount) VALUES (:id, :name)"; Query insert = em.createNativeQuery(sql); sql.setParameter("id", 123); sql.setParameter("name", null); insert.executeUpdate();
It gives PostgreSQL ERROR: column "name" is of type varchar but expression is of type bytea
However using Hibernate specific Session API works:
String sql = "INSERT INTO person (id, name) VALUES (:id, :name)"; Session session = em.unwrap(Session.class); SQLQuery insert = session.createSQLQuery(sql); sql.setInteger("id", 123); sql.setString("name", null); insert.executeUpdate();
It's also mentioned on StackOverflow: http://stackoverflow.com/questions/8211195/postgresql-jdbc-null-string-taken-as-a-bytea
Perhaps related to HHH-9164