Reputation: 720
How can I execute PostgreSQL's sequence manipulation functions, such as setVal()
through Hibernate? For example:
SELECT setval('license_req_seq', (select max (id)+1 as maxVal from agents_requests))
org.hibernate.Session session = ...
session.createSQLQuery(command).executeUpdate()
Upvotes: 1
Views: 660
Reputation: 26502
If you want to obtain the setval procedure returned value then you should use the uniqueResult():
Long nextVal = (Long)session.createSQLQuery(command).uniqueResult();
Upvotes: 1