We're updating the issue view to help you get more done. 

Removing and persisting an entity still fails for proxies

Description

The fix in doesn't work for proxies:

1 2 3 Item item = em.getReference(Item.class, 123); em.remove(item); em.persist(item);
1 2 3 4 5 6 7 8 9 main ] ERROR - 12:51:21,920 - org.hibernate.AssertionFailure: HHH000099: an assertion failure occured (this may indicate a bug in Hibernate, but is more likely due to unsafe use of the session): org.hibernate.AssertionFailure: Unable to perform un-delete for instance org.jpwh.model.simple.Item org.hibernate.AssertionFailure: Unable to perform un-delete for instance org.jpwh.model.simple.Item at org.hibernate.engine.spi.ActionQueue.unScheduleDeletion(ActionQueue.java:527) at org.hibernate.event.internal.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:158) at org.hibernate.event.internal.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:79) at org.hibernate.internal.SessionImpl.firePersist(SessionImpl.java:854) at org.hibernate.internal.SessionImpl.persist(SessionImpl.java:828) at org.hibernate.internal.SessionImpl.persist(SessionImpl.java:832) at org.hibernate.jpa.spi.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:1022)

A related bug is enabled hibernate.use_identifier_rollback, then find() -> remove() -> persist() also doesn't work:

1 2 3 4 5 6 7 8 9 Caused by: org.hibernate.HibernateException: identifier of an instance of org.jpwh.model.simple.Item was altered from 1000 to null at org.hibernate.event.internal.DefaultFlushEntityEventListener.checkId(DefaultFlushEntityEventListener.java:82) at org.hibernate.event.internal.DefaultFlushEntityEventListener.getValues(DefaultFlushEntityEventListener.java:194) at org.hibernate.event.internal.DefaultFlushEntityEventListener.onFlushEntity(DefaultFlushEntityEventListener.java:156) at org.hibernate.event.internal.AbstractFlushingEventListener.flushEntities(AbstractFlushingEventListener.java:229) at org.hibernate.event.internal.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:102) at org.hibernate.event.internal.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:51) at org.hibernate.internal.SessionImpl.flush(SessionImpl.java:1235) at org.hibernate.internal.SessionImpl.managedFlush(SessionImpl.java:405)

Environment

None

Status

Assignee

Brett Meyer

Reporter

Christian Bauer

Fix versions

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

backportDecision

None

Affects versions

4.3.0.Beta3

Priority

Major