Getting ERROR: column "ids" is of type bigint[] but expression is of type text[]

1.7k views Asked by At

I'm getting this error, and I need some guidance to understand what I'm doing wrong.

The error is:

Getting ERROR: column "ids" is of type bigint[] but expression is of type text[]

Now I know that somehow the problem is related to the fact of having the emails field on it.

If i removed the emails field from the java file, then the documentsIds are saved as expected.

This is my entity:

@TypeDef(
        name = "list-array",
        typeClass = ListArrayType.class
    )
public class test{

private List <String> emails;
private List<Long> documentsIds;

@Type(type = "list-array")
@Column(
        name = "emails",
        columnDefinition = "text[]"
    )
public List <String> getEmails(){
    return this.emails;
}
    
@Type(type = "list-array")
@Column(
    name = "ids",
    columnDefinition = "bigint[]"
)
public List<Long> getIds() {
    return this.Ids;
}

And this is the list that I'm trying to save.

List<String> emails = Arrays.asList("sup1", "sup2", "sup3");
List<Long> idsList= Arrays.asList(42L, 9223372036854775800L);
testDao.save(test.builder().emails(emails).ids(idsList).build()));

I'm working with OpenJDK 1.8.0_212, hibernate-types 4.2.9.13, hibernate 4.2.21, and postgress 11.3

Thanks in advance for any suggestions.

1

There are 1 answers

0
lukeraza On BEST ANSWER

I was following an outdated example. If you have the same problem one day, it gets fixed with -->

@TypeDefs({
    @TypeDef(name = "string-list-array", typeClass = ListArrayType.class),
    @TypeDef(name = "long-list-array", typeClass = ListArrayType.class),
})

    @Type(type = "string-list-array")
    @Column(
            name = "emails",
            columnDefinition = "text[]"
        )
    public List <String> getEmails(){
        return this.emails;
    }
    
    @Type(type = "long-list-array")
    @Column(
        name = "ids",
        columnDefinition = "bigint[]"
    )
    public List<Long> getIds() {
        return this.ids;
    }