vladmihalcea / hypersistence-utils

The Hypersistence Utils library (previously known as Hibernate Types) gives you Spring and Hibernate utilities that can help you get the most out of your data access layer.
Apache License 2.0
2.38k stars 365 forks source link

When fetching a List backed by a NULL PostgreSQL array, a NPE is thrown #164

Closed marceloverdijk closed 4 years ago

marceloverdijk commented 4 years ago

I have PostgreSQL table with the following column:

previous_names VARCHAR(255)[] DEFAULT NULL

and mapped it to:

@Entity
@TypeDefs({
        @TypeDef(name = "string-array", typeClass = StringArrayType.class)
})
public class Project {

    @Column(name = "previous_names")
    @Type(type = "string-array")
    private List<String> previousNames = new ArrayList<>();
}

When querying this entity I get:

java.lang.NullPointerException: null
        at java.base/java.lang.reflect.Array.newArray(Native Method) ~[na:na]
        at java.base/java.lang.reflect.Array.newInstance(Array.java:78) ~[na:na]
        at com.vladmihalcea.hibernate.type.array.internal.ArrayUtil.unwrapArray(ArrayUtil.java:199) ~[hibernate-types-52-2.9.0.jar:na]
        at com.vladmihalcea.hibernate.type.array.internal.AbstractArrayTypeDescriptor.wrap(AbstractArrayTypeDescriptor.java:83) ~[hibernate-types-52-2.9.0.jar:na]
        at com.vladmihalcea.hibernate.type.array.internal.ArraySqlTypeDescriptor$2.doExtract(ArraySqlTypeDescriptor.java:55) ~[hibernate-types-52-2.9.0.jar:na]
        at org.hibernate.type.descriptor.sql.BasicExtractor.extract(BasicExtractor.java:47) ~[hibernate-core-5.4.9.Final.jar:5.4.9.Final]

I just upgraded from 2.8.0 to 2.9.0 to be able to map List<String> types instead of String[].

Do I need some other configuration maybe?

marceloverdijk commented 4 years ago

Never mind, I overlooked the ListArrayType.

vladmihalcea commented 4 years ago

The issue could be valid. But I need a replication test case for that.

vladmihalcea commented 4 years ago

Fixed.

marceloverdijk commented 4 years ago

You were quicker fixing it than I could have a look at it ;-) Do you have a plan to release 2.10.0 or could this go in a 2.9.1 bigfix release?

vladmihalcea commented 4 years ago

I could do a 2.9.1 bugfix release as well. I think that's better, as I plan on releasing 2.10.0 only in February.

marceloverdijk commented 4 years ago

That would be appreciated (if you have time to do it).

vladmihalcea commented 4 years ago

I released the 2.9.1 version. You can check it out from Maven Central as soon as it's synced with Sonatype.

amarkin commented 8 months ago

@vladmihalcea, is this issue resolved. We are using hypersistence-utils-hibernate-55 version: 3.7.2 and still getting this error. Implemented the entity mappings exactly as described in here https://vladmihalcea.com/postgresql-array-java-list/

It works fine in my local windows machine, but we get this error when we deploy to other environments. To be exact the Array we are retrieving from DB is not even null.

vladmihalcea commented 8 months ago

If it works fine locally, then for sure the issue is not related to this framework.