我需要将一个bytea类型的数据用于查询时转换成bigint。有什么方法可以实现吗?
更多信息:
我有一个如下的Hibernate仓库 -
@Query(value = "update Sample_Table set other_id = ?1 where id = ?2", nativeQuery = true)
void saveOrUpdateOtherId(Long other_id, Long id);
由于 Hibernate 在 where 子句中将 id
当作 bytea
,而 'Sample_Table' 表的这个 id 字段是 bigint
,因此出现了类型不匹配的问题。
我尝试使用 CAST 将 bytea
转换为 bigint
,但没有成功,错误消息显示无法将 bytea
转换为 bigint
。
如何将 bytea
更改为 bigint
?
编辑:
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;
}
id
字段在这里被定义为长整型。
编辑-2 如果有人遇到这样的问题,很可能是在查询中传递了空值。
bigint
时,我非常怀疑 Spring 在以一种疯狂的方式映射您的 Long。您确定您将一个Long
传递到saveOrUpdateOtherId
函数中吗?您尝试过非本地查询吗?它是否以相同的方式失败? - mabi