How do I have to configure Hibernate Envers with #OneToMany + #JoinColumn?
It uses relation table, but sometimes, records are presented there, sometimes not.
When I fetch from another side of relation (#ManyToOne) - it works, object is presented.
@Entity
@Table(name = "a")
@Audited(targetAuditMode = NOT_AUDITED)
public class A {
@OneToMany(orphanRemoval = true)
@JoinColumn(name = "A_ID", referencedColumnName = "ID")
@MapKeyColumn(name = "SomeEnum")
@MapKeyEnumerated(EnumType.STRING)
@Cascade(CascadeType.ALL)
private Map<SomeEnum, AnotherEntity> anotherEntities = new HashMap<>(0);
As I found in error messages, envers wanted table like this:
CREATE TABLE audit.a_another_entity_aud
(
revtype bigint,
rev bigint,
id bigint,
another_entity_id bigint,
some_enum character varying(255)
)
And table for related entity also
CREATE TABLE audit.another_entity_aud
(
revtype bigint,
rev bigint,
id bigint,
a_id bigint,
some_enum character varying(200)
)
Also, how can I audit #ElementCollection of enums? mapping like:
public class Role {
#ElementCollection
#CollectionTable(name = "role_permissions", joinColumns = #JoinColumn(name = "ROLE_ID"))
#Column(name = "PERMISSION_NAME")
#Enumerated(EnumType.STRING)
private Set<Permission> permissions;
}
If I audit it like
CREATE TABLE audit.role_permissions_aud (
revtype bigint,
rev bigint,
role_id bigint,
permission_code character varying(255)
);
I do only get diff
But there’re actually another “permissions”
(at) is replaced with # hash, because can’t post with 2+ “user mentions”