-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Hibernate query
PostPosted: Thu Aug 18, 2005 12:45 am 
Newbie

Joined: Thu Aug 18, 2005 12:20 am
Posts: 1
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:

Mapping documents:

Code between sessionFactory.openSession() and session.close():

Full stack trace of any exception that occurs:

Name and version of the database you are using:

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:

Hi,

I need some help in writing queries in hibernate as i am new to it.
I have a table with columns as userID , serialNo, userName
with userID and serialNo as composite primary key.
I need to select the records having the maximum serialNo group by userID, ie, i need to get records with unique userID having the maximum serialNo.

Pls help me in writhing the query,

Thanks in advance.

Sunil.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 18, 2005 4:47 am 
Expert
Expert

Joined: Thu May 26, 2005 9:19 am
Posts: 262
Location: Oak Creek, WI
Hi Sunil

Go thorugh the below code. You can do it using Criteria

List results = session.createCriteria(YourClass.class)
.setProjection( Projections.projectionList()
.add( Projections.max("serialNo ")
.add( Projections.groupProperty("userID"))
.list();

For reference look into the below link

http://www.hibernate.org/hib_docs/v3/re ... projection

Try this Out.

_________________
RamnathN
Senior Software Engineer
http://www.linkedin.com/in/ramnathn
Don't forget to rate.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.