Gaurav
Gaurav

Reputation: 1516

Hibernate read only session - updating entities

We have set all our sessions to read only by calling setDefaultReadOnly(true). However our updates no longer work even after we explicitly call session.update(entity). I can see why this is happening, hibernate does not know that this entity is dirty.

My question is, how can I tell hibernate that I have made changes to this entity which need to be sync'd back? I tried merging the entity with session.merge(entity) but that didn't work.

Upvotes: 1

Views: 5443

Answers (2)

sharakan
sharakan

Reputation: 6901

Before you change the state of the entity, make it not read-only: session.setReadOnly(entity, false)

Then edit the entity, and let flush/commit do dirty checking as per usual.

Upvotes: 1

Grim
Grim

Reputation: 1974

Try this:

session.refresh(entity)

Upvotes: 0

Related Questions