Issue Type: Bug Bug
Affects Versions: 3.6.7
Assignee: Unassigned
Components: core
Created: 28/Jun/12 3:52 AM
Description:

When an entity is read using a read-only HQL query, if you run a Session.get() for that entity with LockOptions.UPGRADE you get a ObjectDeletedException.

The reason of the failure is that the EntityEntry has status READ after the HQL query, and when the lock mode is upgraded in the Session.get(), AbstractLockUpgradeEventListener thinks that the READ status is wrong, throwing the ObjectDeletedException.

I think that a READ_ONLY entity should be moved to MANAGED if you lock it. Or, otherwise, advice in the docs that a READ_ONLY entity can't be locked.

Stacktrace:

org.hibernate.ObjectDeletedException: attempted to lock a deleted instance: [...]
at org.hibernate.event.def.AbstractLockUpgradeEventListener.upgradeLock(AbstractLockUpgradeEventListener.java:67)
at org.hibernate.event.def.DefaultLoadEventListener.loadFromSessionCache(DefaultLoadEventListener.java:551)
at org.hibernate.event.def.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:440)
at org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:227)
at org.hibernate.event.def.DefaultLoadEventListener.lockAndLoad(DefaultLoadEventListener.java:403)
at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:155)
at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:1090)
at org.hibernate.impl.SessionImpl.get(SessionImpl.java:1081)

Project: Hibernate ORM
Priority: Major Major
Reporter: Miguel Diaz
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators.
For more information on JIRA, see: http://www.atlassian.com/software/jira