-->
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.  [ 4 posts ] 
Author Message
 Post subject: get maximum number
PostPosted: Thu Jul 31, 2008 5:50 am 
Newbie

Joined: Thu Jul 31, 2008 5:33 am
Posts: 5
I saved a record into a table.Once saved,i Like to get the object ID (maximum of ID in table) ,pLease suggest how it can be done?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 31, 2008 8:10 am 
Newbie

Joined: Thu Jul 17, 2008 2:35 am
Posts: 5
hi,

just execute the following query you will get the max value

select max(alias.columnname) from TableName as alias

Hope this may help you


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 31, 2008 9:24 am 
Newbie

Joined: Thu Jul 31, 2008 5:33 am
Posts: 5
thanks for ur reply.In my code I use the statement "hibernateTemplate.save(transientInstance)".Once saved ,I will execute the
"select max(alias.columnname) from TableName".In my application,it has many table,for every table i have to execute the query once data saved?.Is there any easy approach for this?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 01, 2008 2:45 am 
Newbie

Joined: Wed Jul 30, 2008 7:48 am
Posts: 10
Location: NOIDA
SessionFactory factory = new Configuration().configure().buildSessionFactory();
sess = factory.openSession();
String queryStr = "select
max(columnName)from Object";
Query query = sess.createQuery(queryStr);
List list = query.list();
System.out.println("max value of that column is : " + list.get(0));
sess.close();


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.