Select nvl(max(c.EmployeeId),0) in JPQL?

J. Bend picture J. Bend · Aug 1, 2009 · Viewed 22.1k times · Source

I'm using oracle10g database and eclipselink, I need to obtain the last inserted key from the table so i've created this query

javax.persistence.Query q =   
                    em.createQuery("SELECT nvl(MAX(c.myAtt),0) " +   
                        "from myTable as c");   
             return Integer.parseInt(q.getSingleResult().toString());   `

But when the table is empy(sometimes it might get empty) i'm getting ILEGAL ARGUMENT EXCEPTION, cause: JPQL Exception, detail: "An exception occurred while creating a query in EntityManager". What i'm doing wrong?

Answer

Robar picture Robar · May 5, 2010

In the meanwhile somebody else could have inserted something in Autorizaciones and then you receive the wrong id