| Here are two entities:
@Entity
@Audited
public static class SomeEntity
{
@Id
@GeneratedValue
@Column
@RevisionNumber
private Long id;
@ElementCollection(fetch = FetchType.LAZY)
private Map<OtherEntity, Status> map = new HashMap<>();
public Long getId()
{
return id;
}
public void setId(Long id)
{
this.id = id;
}
public Map<OtherEntity, Status> getMap()
{
return map;
}
public void setMap(Map<OtherEntity, Status> map)
{
this.map = map;
}
public enum Status
{
A,
B
}
}
@Entity
@Audited
public static class OtherEntity
{
@Id
@GeneratedValue
@Column
@RevisionNumber
private Long id;
public Long getId()
{
return id;
}
public void setId(Long id)
{
this.id = id;
}
}
Note that the key of the map is an entity. When running the following code:
/*
* Put new stuff in database
*/
Session session = openSession();
session.getTransaction().begin();
SomeEntity someEntity = new SomeEntity();
session.save(someEntity);
OtherEntity otherEntity = new OtherEntity();
session.save(otherEntity);
someEntity.getMap().put(otherEntity, SomeEntity.Status.A);
session.getTransaction().commit();
/*
* Attempt to update map
*/
session.getTransaction().begin();
CriteriaQuery<SomeEntity> query1 = session.getCriteriaBuilder().createQuery(SomeEntity.class);
query1.select(query1.from(SomeEntity.class));
someEntity = session.createQuery(query1).getSingleResult();
CriteriaQuery<OtherEntity> query2 = session.getCriteriaBuilder().createQuery(OtherEntity.class);
query2.select(query2.from(OtherEntity.class));
otherEntity = session.createQuery(query2).getSingleResult();
someEntity.getMap().put(otherEntity, SomeEntity.Status.B);
session.getTransaction().commit();
session.close();
the following exception is thrown with Hibernate 5.2.11 while attempting to commit the second transaction:
This used to work with Hibernate 5.2.10. This example has also been attached as a test case. When adding the @NotAudited annotation to SomeEntity#map, the test does not fail. |