I want to fetch the last inserted value\'s id in Hibernate.
After search:
Long lastId = ((Long) session.createSQLQuery(\"SELECT LAST_INSERT_ID()\").
public Integer save(Smartphones i) { int id = 0; Session session=HibernateUtil.getSessionFactory().openSession(); Transaction trans=session.beginTransaction(); try{ session.save(i); id=i.getId(); trans.commit(); } catch(HibernateException he){} return id; }