No Dialect mapping for JDBC type: 2003
Hibernate does not provide and Converter class/Mapper class to convert DB text[] datatype, For this either we can write our own converted type implementing UserType or we using sqlQuery.addScalar( "path", Hibernate.TEXT ); we can map text[] to text and then in java code we can split it from ','
This is how I have solved the issue in SpringBoot:
- Add dependency to
pom.xml
:
<dependency>
<groupId>com.vladmihalcea</groupId>
<artifactId>hibernate-types-52</artifactId>
<version>2.11.1</version>
</dependency>
- Extend your Hybernate Dialect as follows:
import com.vladmihalcea.hibernate.type.array.StringArrayType;
import org.hibernate.dialect.PostgreSQL94Dialect;
public class PostgreSQL94CustomDialect extends PostgreSQL94Dialect {
public PostgreSQL94CustomDialect() {
super();
this.registerHibernateType(2003, StringArrayType.class.getName());
}
}
- Specify the
PostgreSQL94CustomDialect
inapplication.properties
:
spring.jpa.properties.hibernate.dialect=com.package.name.PostgreSQL94CustomDialect
Use a package 'com.vladmihalcea:hibernate-types-52:2.8.0' or add your database dialect to yml file in resources:
@Entity
@TypeDefs({
@TypeDef(name = "string-array", typeClass = StringArrayType.class),
@TypeDef(name = "json", typeClass = JsonStringType.class),
@TypeDef(name = "jsonb", typeClass = JsonBinaryType.class)
})
public class Post implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Type(type = "string-array")
@Column(columnDefinition = "text[]")
private String[] tags;
One possibility for problem resolution use "UNNEST" postgree function, this can be used as a hint:
SELECT UNNEST({acl_3_3,acl3_4,acl3,acl_3_3})