Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hibernate Session.save() doesn't return a value?

Tags:

java

hibernate

Below code throws a casting error

Long newID = (Long)session.save(object);

I am new to hibernate. Don't know why.

like image 937
Dustin Sun Avatar asked Nov 27 '10 05:11

Dustin Sun


1 Answers

The return value of session.save() depends on your mapping. Most likely you have a type of ID that isn't a Long. Try doing this:

System.out.println(session.save(object).getClass().getName());

Then you'll see the type name.

like image 137
Martin Algesten Avatar answered Sep 28 '22 09:09

Martin Algesten