如何通过Hibernate执行PostgreSQL的sequence manipulation functions,如setVal()?例如:

SELECT setval('license_req_seq', (select max (id)+1 as maxVal from agents_requests))

org.hibernate.Session session = ...
session.createSQLQuery(command).executeUpdate()

最佳答案

如果要获取setval过程返回的值,则应使用uniqueResult():

Long nextVal = (Long)session.createSQLQuery(command).uniqueResult();

10-06 02:09