Sintaxe nextval postgre no EntityManager.createQuery

2 respostas
A

Pessoal,

Alguém pode me ajudar com a sintaxe do nextval postgre no createQuery do EntityManager???
Já estou desesperado…
(desenvolvimento web com JEE, EJB, JPA e JSF)

Estou fazendo assim:

public Integer getIdPessNextval(){ Query q = getEntityManager().createQuery("select nextval('pessoa_idpess_seq');"); return (Integer) q.getSingleResult(); }

E está aparecendo a seguinte página de erro:

Caused by: java.lang.IllegalArgumentException: An exception occurred while creating a query in EntityManager: Exception Description: Syntax error parsing the query [select nextval('pessoa_idpess_seq');], line 1, column 14: syntax error at [(]. Internal Exception: MismatchedTokenException(81!=32)

A pricipio parece que a query está certa, mas aparece este erro no parentese…
Aguém pode me ajudar por favor???
Grato!

2 Respostas

jamirdeajr

Alan, creio que você teria que utilizar CreateNativeQuery em vez de CreateQuery, já que nextval é específico do PostgreSQL.

A

jamirdeajr,

Fiz o que sugeriu e funcionou perfeitamente…
Muito obrigado pelo help!
:smiley:

Criado 21 de março de 2011
Ultima resposta 22 de mar. de 2011
Respostas 2
Participantes 2