Monday, February 21, 2011

how to query last inserted Guid in hibernate

hi can any body tell me how i can get the last in serted id in hibernate like in my sql i used the query like this:=="SELECT LAST_INSERT_ID()"

how i can represent this in hibernate

thanks in advance

From stackoverflow
  • 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();  
    
  • thanks actually i got the solution inthis way

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

    but i have another doubt

    can u tell me how i can update my data from a table with 2 where condition and i have no primary key even if the primary key is there i am not using that one thanks

0 comments:

Post a Comment