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

Replicating detached instance from Envers fails with NPE if bytecode is instrumented

Description

I've not been able to reproduce this issue without Envers, so the problem might be there. The test passes if you don't instrument bytecode.

This routine is one of the more important use cases for replicate(), this is how you can roll back to a historical revision with Envers:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 Long USER_ID; { tx.begin(); EntityManager em = JPA.createEntityManager(); User user = new User("johndoe"); em.persist(user); tx.commit(); em.close(); USER_ID = user.getId(); } { tx.begin(); EntityManager em = JPA.createEntityManager(); AuditReader auditReader = AuditReaderFactory.get(em); Number revisionCreate = auditReader.getRevisionNumberForDate(new Date()); User user = auditReader.find(User.class, USER_ID, revisionCreate); em.unwrap(Session.class).replicate(user, ReplicationMode.OVERWRITE); tx.commit(); em.close(); }
1 2 3 4 5 6 7 8 9 Caused by: java.lang.NullPointerException at org.hibernate.engine.spi.EntityEntry.isUnequivocallyNonDirty(EntityEntry.java:314) at org.hibernate.engine.spi.EntityEntry.requiresDirtyCheck(EntityEntry.java:296) at org.hibernate.event.internal.DefaultFlushEntityEventListener.onFlushEntity(DefaultFlushEntityEventListener.java:154) 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:1242) at org.hibernate.internal.SessionImpl.managedFlush(SessionImpl.java:412)

Environment

None

Status

Assignee

Unassigned

Reporter

Christian Bauer

Fix versions

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

4.3.0.Beta4

Priority

Minor