Tutorial :How can I get the last inserted Guid in Hibernate?



Question:

Can anybody tell me how I can get the last inserted ID in Hibernate? In MySQL I used a query like SELECT LAST_INSERT_ID().


Solution:1

Why you need this is unclear but it should be possible using a native query. Something like that:

Integer lastId = (Integer) session.createSQLQuery("SELECT LAST_INSERT_ID()")      .uniqueResult();    


Solution:2

I got the solution this way:

lSession.flush();  long lAddGUID = lObjAddressTable.getUserGUID();  pObjAddressDetails.setUserGUID(lAddGUID);  if(0 != lAddGUID ){                  lRetVal = true;  }  

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »