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


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().


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();    


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
Next Post »