The-Alchemist / hibernate-postgresql

extra type mapping for PostgreSQL-specific types such as hstore and inet
Apache License 2.0
30 stars 5 forks source link

Nullpointer using inet-type #9

Open hannez82 opened 7 years ago

hannez82 commented 7 years ago

I get a nullpointer when using the inet-type on postgres 10/jdbc-4.2.1.4 Caused by: java.lang.NullPointerException at org.postgresql.jdbc.TypeInfoCache.getOidStatement(TypeInfoCache.java:256)

Updating the method nullSafeSet to:

  @Override
    public void nullSafeSet(PreparedStatement preparedStatement, Object o, int i, SessionImplementor sessionImplementor) throws HibernateException, SQLException {

        if (o == null) {
            preparedStatement.setNull(i, java.sql.Types.OTHER);
        } else {
            PGobject object = new PGobject();
            object.setValue(((InetAddress) o).getHostAddress());
            **object.setType("inet");**
            preparedStatement.setObject(i, object);
        }
    }

Fixes the problem

The-Alchemist commented 7 years ago

Could you submit a PR?

Thanks!