Kevin
Kevin

Reputation: 6292

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.

Upvotes: 0

Views: 262

Answers (1)

Suresh Atta
Suresh Atta

Reputation: 121998

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.

Upvotes: 4

Related Questions