【发布时间】:2020-11-02 02:12:40
【问题描述】:
我在 postgres 中创建了域:
create domain arrayofids as numeric[];
现在我想像这样在 spring 数据中使用域:
String fakeQuery = "unnest(CAST (:ids AS arrayofids))";
Query nativeQuery = entityManager.createNativeQuery(fakeQuery);
BigInteger[] arrayOfids = new BigInteger[] {new BigInteger("1"),new BigInteger("2)} //or It can be List. It is not important
nativeQuery.setParameter("ids", arrayOfids);
List resultList = nativeQuery.getResultList();
当然我得到错误:
org.postgresql.util.PSQLException: ERROR: cannot cast type bytea to arrayofIds
在我使用 https://dalesbred.org/docs/api/org/dalesbred/datatype/SqlArray.html 之前,它运行良好,或者我自己在 JDBC 中进行了自定义类型。 Hibernate 不允许轻松使用我的域。
这样查询:
select * from mtTbale where id in :ids
不感兴趣。我应该使用带有 unnest 和 CAST 的域
【问题讨论】:
标签: postgresql hibernate jpa spring-data nhibernate-mapping