Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to map an array of custom type from postgres to java using hibernate

I am trying to map an array of custom type returned by a postgres procedure to the java

I have a custom type in postgres as

CREATE TYPE public.customtype_sample AS(
    sampleid bigint,
    samplename character varying,
    samplevalue character varying
)

The procedure returns an array of customtype_sample as column of type customtype_sample[] in postgres

I went through various link: How to map User Data Type (Composite Type) with Hibernate

Array with UserType in Hibernate and PostgreSQL --> MappingException

and may more wrote a class that implements array of sampletype but i end up getting this exception

"could not execute query" 

caused by : org.postgresql.util.PSQLException: Method org.postgresql.jdbc4.Jdbc4Array.getArrayImpl(long,int,Map) is not yet implemented.

The error occurs in the nullSafeGet method of the userType

@Override
    public Object nullSafeGet(ResultSet rs, String[] names,
            SessionImplementor session, Object owner)
            throws HibernateException, SQLException {
        SampleType[] javaArray = null;
        Array array = (Array) rs.getArray(names[0]);
         if (!rs.wasNull()) {
         javaArray = (SampleType[]) array.getArray();//error occurs here 
         }
         return toReferenceType(javaArray);

    }

seems when i am trying to get the array of custom type there might be some problem not able to understand how to write usertype class for an array of customtype. Any help will be appreciated.

like image 999
Lakshmi Avatar asked Nov 02 '22 16:11

Lakshmi


1 Answers

Had the same error, and I fixed it by upgrading PostgreSQL JDBC from 9.2-1002-jdbc4 to 9.4-1201-jdbc41

like image 133
Alex G Avatar answered Nov 09 '22 09:11

Alex G