【发布时间】:2016-06-14 01:49:06
【问题描述】:
我正在使用 Hibernate4 + PostgresSql。 我需要从我的数据库中获取 id 列表而不获取整个对象。 我使用原生查询(因为它是分层的),它看起来像:
String s = hierachical_part_skipped +"select id " +
"from search_hierarchy " +
"order by id";
Query q = getEntityManager().createNativeQuery(s);
List<Long> resList = new ArrayList<>();
List<BigInteger> biglist = q.getResultList();
for (Object id : biglist) {
System.out.print(id+",");
resList.add(id.longValue());
}
好吧,我的 bigList 中有 1 次填充了错误的值! 我有 10,20,30,40,50,60,70,80,90,100 ... 27350 代替 1, 2... 2735 (每个值都添加一个零)。 不通过 Hibernate 手动执行的本机查询返回正确的值。
我尝试将结果作为对象列表检索,但结果相同
【问题讨论】:
-
删除一个将 id 值乘以十的触发器。
-
@Roman C,你在说什么触发器,为什么它有时只工作?
标签: java sql hibernate postgresql