最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

java - Caused by: PSQLException: ERROR: column "columnName" is of type text[] but expression is of type charac

programmeradmin4浏览0评论
Caused by: .postgresql.util.PSQLException: ERROR: column "columnName" is of type text[] but expression is of type character varying
  Hint: You will need to rewrite or cast the expression.
  Position: 433
    at .postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2713)
    at .postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2401)
    at .postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:368)
    at .postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:498)
    at .postgresql.jdbc.PgStatement.execute(PgStatement.java:415)
    at .postgresql.jdbc.PgPreparedStatement.executeWithFlags(PgPreparedStatement.java:190)
    at .postgresql.jdbc.PgPreparedStatement.executeUpdate(PgPreparedStatement.java:152)
    at .hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:275)
    ... 59 more

DB column :

@Convert(converter = StringArrayConverter.class)
    @Column(name = "columnName", columnDefinition = "text[]")
    private String[] gvcBrands = new String[0];

Converter Class:

package com.coral.epos2.customers.model;
    
    import jakarta.persistence.AttributeConverter;
    import jakarta.persistence.Converter;
    
    @Converter(autoApply = true)
    public class StringArrayConverter implements AttributeConverter<String[], String> {
    
        @Override
        public String convertToDatabaseColumn(String[] attribute) {
            
        }
    
        @Override
        public String[] convertToEntityAttribute(String dbData) {
           
        }
    }

I am getting above error when we want to insert the data into db. Please help me to write the proper converter class.

Caused by: .postgresql.util.PSQLException: ERROR: column "columnName" is of type text[] but expression is of type character varying
  Hint: You will need to rewrite or cast the expression.
  Position: 433
    at .postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2713)
    at .postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2401)
    at .postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:368)
    at .postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:498)
    at .postgresql.jdbc.PgStatement.execute(PgStatement.java:415)
    at .postgresql.jdbc.PgPreparedStatement.executeWithFlags(PgPreparedStatement.java:190)
    at .postgresql.jdbc.PgPreparedStatement.executeUpdate(PgPreparedStatement.java:152)
    at .hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:275)
    ... 59 more

DB column :

@Convert(converter = StringArrayConverter.class)
    @Column(name = "columnName", columnDefinition = "text[]")
    private String[] gvcBrands = new String[0];

Converter Class:

package com.coral.epos2.customers.model;
    
    import jakarta.persistence.AttributeConverter;
    import jakarta.persistence.Converter;
    
    @Converter(autoApply = true)
    public class StringArrayConverter implements AttributeConverter<String[], String> {
    
        @Override
        public String convertToDatabaseColumn(String[] attribute) {
            
        }
    
        @Override
        public String[] convertToEntityAttribute(String dbData) {
           
        }
    }

I am getting above error when we want to insert the data into db. Please help me to write the proper converter class.

Share Improve this question asked Feb 17 at 5:38 Debasish HalderDebasish Halder 1851 gold badge3 silver badges14 bronze badges 1
  • 1 You appear to be converting String[] into String when mapping to the database, but the database column is an array. Can you explain why you are doing this? – Richard Huxton Commented Feb 17 at 7:08
Add a comment  | 

1 Answer 1

Reset to default 1

Remove StringArrayConverter class. You don't need it.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论