Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to select last inserted record from Table Using HQl

 
jidhendra kumar
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI All,

I am Beginner to Hibernate,I have a problem.
Usually after inserted a new record in Table , I want to select the same record from table Using HQL.

Prestetly i am implementing this as following method.

for example.
Table Employee
cols: empno empname
1001 Suresh
1004 Magesh

Here empno is Auto generated. I don't know what is the no i am inserting.
If i am inserted a new row.(mickel);

I want to select the same record after insertion.

Now i am doing following way.

select max(empno) from employee;
then
select * from employee where empno='1005';

But i want to make this meaningful by selecting within single stmt.



If any one know the solutions for this please share your view with me..


With Regards,
M. Jidhendra Kumar.
 
Praveen Kumar
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Lets say that you are inserting using the following statement

session.saveOrUpdate(Employee employee)

You do not have to retrieve it again. The object employee would still be available for further modifications or references.

Anyway, if you do want to retrieve for some reason, you could also do something like below ...

(Select * From Employee emp WHERE emp.empno =(Select max(empno)from Employee));

Hope this helps,

Praveen
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic