*
The moose likes Object Relational Mapping and the fly likes A Query won't give me the Integer value Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "A Query won Watch "A Query won New topic
Author

A Query won't give me the Integer value

Dave Elwood
Ranch Hand

Joined: Dec 27, 2002
Posts: 84
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
Jayesh A Lalwani
Bartender

Joined: Jan 17, 2008
Posts: 2271
    
  28

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

Joined: Dec 27, 2002
Posts: 84
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??
Sameer Mali
Greenhorn

Joined: Dec 22, 2012
Posts: 2

try using
Dave Elwood
Ranch Hand

Joined: Dec 27, 2002
Posts: 84
Thank you Sameer, now it works like a charm.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: A Query won't give me the Integer value
 
Similar Threads
Serious error in JPA with @Version
jsf navigation and database connection
EJB3 Entity Bean won't verify with Netbeans
Creating a MySQL table and Entity from Database.
Trying to figure out how to use MySQL and generated @Id