简体   繁体   中英

Hibernate: How to get new id created as a result of insert

I have a hibernate code which insert a new role to the table as follows:

    Staff staff = new Staff(staffDTO);
    Session session = sessionManager.getSession();
    session.beginTransaction();
    session.save(staff);
    session.getTransaction().commit();

Staff is defined as entity.

My question is that how can I get the newly generated row id by the database?

Many thanks.

Hibernate is smart enough :).

After you save the Object in database If you see ,the object have the generated id. Check it.

After save done, just inspect the object and see.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM