• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

A Query won't give me the Integer value

 
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm writing a JavaEE6 app using NetBeans and persisting the entities on Glassfish
I've got a table of rooms with the Entity Room class to access the data.
The primary key is room_id and I need to find the last value used in order to bump up
the value and then insert a new room record.

So...in order to find the last value used I have a named query which calls the aggregate function MAX

In the session bean I fetch the value this way

Is there a member function of the Query object which returns the value MAX(r.roomId) ??
Something like :

this is what the whole Entity class looks like
 
Rancher
Posts: 2759
32
Eclipse IDE Spring Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When you say, "doesn't work", what error do you get? Is it a compilation error? Is it a runtime error?
 
Dave Elwood
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It compiles and runs, but there are three records, and the last record has room_id = 3 but this returns a value of 0
when I use

then I get a value of 2147483647

How do I get it to show me the value of 3??
 
Greenhorn
Posts: 2
Netbeans IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
try using
 
Dave Elwood
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Sameer, now it works like a charm.
reply
    Bookmark Topic Watch Topic
  • New Topic