Solution assumes that PostUpdateEvent#getOldState() method returns database state before modifications. Note that object's non-updateable properties are not re-initialized with database values after executing EntityManager#find() method. Use EntityManager#refresh() instead.
// Revision 2
em.getTransaction().begin();
entity = em.find(PropertyNotUpdatableEntity.class, entity.getId());
entity.setData("modified data");
entity.setConstantData1(null); // @Column(updatable = false)
em.merge(entity);
em.getTransaction().commit();
// Revision 3
em.getTransaction().begin();
entity = em.find(PropertyNotUpdatableEntity.class, entity.getId()); // Use EntityManager#refresh() instead.
// Here entity.getConstantData1() returns null and it will cause Envers to operate incorrectly (put null in the audit table).
em.getTransaction().commit();
If described behavior is unacceptable, please reopen this ticket. To fix this I would have to execute SELECT statement to retrieve actual values for all non-updateable columns before saving audit data (decreases performance).
Solution assumes that PostUpdateEvent#getOldState() method returns database state before modifications. Note that object's non-updateable properties are not re-initialized with database values after executing EntityManager#find() method. Use EntityManager#refresh() instead.
If described behavior is unacceptable, please reopen this ticket. To fix this I would have to execute SELECT statement to retrieve actual values for all non-updateable columns before saving audit data (decreases performance).