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

Popular posts from this blog

c - Mpirun hangs when mpi send and recieve is put in a loop -

python - Apply coupon to a customer's subscription based on non-stripe related actions on the site -

java - Unable to get JDBC connection in Spring application to MySQL -