java - How can I get last inserted id using Hibernate -
I want to get last entered value ID in hibernate
after searching:
long last id = ((long) session .createSQLQuery ("SELECT LAST_INSERT_ID ()"). UniqueResult ()). LongValue (); But the following code gives me this error:
java.lang.ClassCastException: do not insert java.math.BigInteger on java.lang.Long Solution long last id = ((BigIntega) session. CreateSQLQuery (" SELECT LAST_INSERT_ID () "). Exclusive Result ()). LongValue (); Do not forget to import:
Import java.math.BigInteger;
The error is very clear it is returning and not long You have to specify it to someone. And get from it.
Comments
Post a Comment