Satish Mishra
Satish Mishra

Reputation: 23

Do we need to begin transaction before making any changes in persistent objects?

Can I use transaction like below:

persistentObj.setValue("xyz");
session.beginTransaction().commit();

assuming session is created before fetching object from database?

Upvotes: 2

Views: 331

Answers (1)

Linh Nguyen
Linh Nguyen

Reputation: 659

As you write above, only the object is changed. It will not be persisted to the database.

You must call persist() or saveOrUpdate() method to make changes to object. You should also follow this order: begin transaction, update or save, and then commit.

Upvotes: 1

Related Questions