小编Man*_*kla的帖子

postgresql:将bytea转换为bigint

我必须将查询的bytea条目转换为bigint.怎么可以这样做?

更多信息:

我有一个hibernate存储库,如下所示 -

 @Query(value = "update Sample_Table set other_id = ?1 where id = ?2", nativeQuery = true)
 void saveOrUpdateOtherId(Long other_id, Long id);
Run Code Online (Sandbox Code Playgroud)

Hibernate以某种方式取id(在where子句中)bytea,因为' Sample_Table '具有此id字段bigint,因此它会抛出类型不匹配问题.

我已经尝试使用CAST转换byteabigint但它没有成功,错误msg说bytea无法转换为bigint.

我怎样才能改变byteabigint


编辑:

Sample_Table DAO:

@Table(name = "Sample_Table")
public class Sample{
    @Id
    @Column(name = "id", unique = true)
    @GeneratedValue
    private Long id;

    @Column(name = "other_id")
    private Long other_id;
}
Run Code Online (Sandbox Code Playgroud)

id field在这里定义为Long.


编辑-2 如果有人遇到这样的问题,他很可能在查询中传递空值.

postgresql hibernate jpa postgresql-9.1

7
推荐指数
2
解决办法
2938
查看次数

标签 统计

hibernate ×1

jpa ×1

postgresql ×1

postgresql-9.1 ×1