hibernate 原因:org.postgresql.util.PSQLException:错误:列“low_range”的类型为Double Precision,但表达式的类型为BYTEA

sq1bmfud  于 2022-11-14  发布在  PostgreSQL
关注(0)|答案(1)|浏览(341)

我有这样一个实体:

@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Builder(toBuilder = true)
@Entity
@Table(name = "words")
public class Words implements Serializable {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id", unique = true, updatable = false, nullable = false)
    private long id;

    @Column(name = "keyword", length = 200, unique = true)
    private String keyword;

    @Column(name = "low_range", length = 100)
    private BigDecimal lowRange;

    @Column(name = "high_range", length = 100)
    private BigDecimal highRange;
}

我使用此查询进行SQL更新:

@Modifying
@Query(value="update processed_words set low_range = :lowRange, high_range = :highRange where keyword = :keyword", nativeQuery = true)
int updateByKeyword(@Param("keyword") String keyword,
                    @Param("lowRange") BigDecimal lowRange,
                    @Param("highRange") BigDecimal highRange);

PostgreSQL表:

CREATE TABLE IF NOT EXISTS public.words
(
    id bigint NOT NULL DEFAULT nextval('words_id_seq'::regclass),
    keyword character varying(200) COLLATE pg_catalog."default",
    high_range double precision,
    low_range double precision
)

当我执行UPDATE查询时,我得到以下异常:

Caused by: org.postgresql.util.PSQLException: ERROR: column "low_range" is of type double precision but expression is of type bytea
  Hint: You will need to rewrite or cast the expression.

您知道如何解决此问题吗?

vxf3dgd4

vxf3dgd41#

您可能希望使用‘DECIMAL’或‘NUMERIC’列类型,而不是‘DOUBLE PRECISION’。您还需要根据存储的值指定精度。
你可以在https://www.postgresql.org/docs/current/datatype-numeric.html#DATATYPE-NUMERIC-DECIMAL上看到这一消息

相关问题