I am using Spring MVC + Hibernate
@Resource(name = "sessionFactory")
private SessionFactory sessionFactory;
// save
public <T> int save(T entity) throws DataAccessException {
Session session = sessionFactory.getCurrentSession();
session.save(entity);
}
As New Record Save , New Primary Key generated which in auto increment (db.MySQL). I want to get and return the new auto incremented value with respect to the above method.
Update me !
Try this instead. This works with latest Hibernate (version 4.1) also.
session.persist(object);
object.getId();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With