Gilo
Gilo

Reputation: 720

How to run SEQUENCE setVal from Hibernate

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

Answers (1)

Maciej Kowalski
Maciej Kowalski

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

Related Questions