Because of an purpose, I need to get an id of an object right after an insertion. I can work around with this code:
session.save(Object o) // insert to d
By default, hibernate framework will immediately return id , when you are trying to save the entity using Save(entity) method. There is no need to do it explicitly.
In case your primary key is int you can use below code:
int id=(Integer) session.save(entity);
In case of string use below code:
String str=(String)session.save(entity);