| Hello I think I discovered a bug in envers while using a Map<enum, entity>. Envers does not produce the KEY column in the database and also forgets the additional Update query during auditing. It might also just be a configuration issue so I'm posting the related model and mappings: While the operationDetails table contains the column operationdetails_KEY the corresponding audit table does not. From what I can see there is neither an audit join table created. (probably that is the issue?) The system runs fine in general. I just discovered this issue while trying to integration Javers to be able to build diffs from two audit query results. As the key-information is missing we end up with a map containing ONE null key with one OperationDetails.
@Entity
@Audited
@Table(name = "operation")
public class Operation extends VersionedEntity {
@OneToMany(mappedBy = "operation", fetch = FetchType.LAZY)
@Cascade(CascadeType.ALL)
@MapKeyEnumerated(EnumType.STRING)
private Map<OperationDetailsType, OperationDetails> operationDetails;
}
@Entity
@Audited
@Table(name = "operationdetails")
public class OperationDetails extends BaseEntity {
@ManyToOne(fetch = FetchType.LAZY, optional = false)
@JoinColumn(name = "operation_id", nullable = false)
@NotNull
private Operation operation;
}
create table operation (id integer not null, uuid varchar(40) not null, version integer, created_date timestamp not null, emailnotification boolean not null, modified_date timestamp not null, status varchar(255) not null, description varchar(2000) not null, target varchar(255) not null, creator_id integer not null, scope_id integer not null, currenttask_id integer not null, executor_id integer not null, primary key (id));
create table operationdetails (id integer not null, uuid varchar(40) not null, details varchar(1000), operation_id integer not null, operationdetails_KEY varchar(255), primary key (id));
create table Z_AUD_operation (id integer not null, REV integer not null, REVTYPE tinyint, uuid varchar(255), created_date timestamp, emailnotification boolean, modified_date timestamp, status varchar(255), description varchar(255), target varchar(255), creator_id integer, scope_id integer, currenttask_id integer, executor_id integer, primary key (id, REV));
create table Z_AUD_operationdetails (id integer not null, REV integer not null, REVTYPE tinyint, uuid varchar(255), details varchar(1000), operation_id integer, primary key (id, REV));
public class Test {
public void create() {
Operation operation = new Operation();
OperationDetails od = new OperationDetails();
od.setOperation(operation);
operation.getOperationDetails().put(OperationDetailsType.FIRST, od);
od = new OperationDetails();
od.setOperation(operation);
operation.getOperationDetails().put(OperationDetailsType.SECOND, od);
}
}
2017-06-08 21:48:58,774 [main] DEBUG o.h.SQL - call next value for operation_SEQ
2017-06-08 21:48:58,776 [main] DEBUG o.h.SQL - call next value for operationdetails_SEQ
2017-06-08 21:48:58,778 [main] DEBUG o.h.SQL - call next value for operationdetails_SEQ
2017-06-08 21:48:58,791 [main] DEBUG o.h.SQL - insert into operation (uuid, version, created_date, creator_id, emailnotification, modified_date, status, scope_id, currentTask_id, description, executor_id, target, id) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
2017-06-08 21:48:58,801 [main] DEBUG o.h.SQL - insert into operationdetails (uuid, details, operation_id, id) values (?, ?, ?, ?)
2017-06-08 21:48:58,807 [main] DEBUG o.h.SQL - insert into operationdetails (uuid, details, operation_id, id) values (?, ?, ?, ?)
2017-06-08 21:48:58,810 [main] DEBUG o.h.SQL - update operationdetails set operationDetails_KEY=? where id=?
2017-06-08 21:48:58,811 [main] DEBUG o.h.SQL - update operationdetails set operationDetails_KEY=? where id=?
2017-06-08 21:48:58,849 [main] DEBUG o.h.SQL - update operation set version=?, created_date=?, creator_id=?, emailnotification=?, modified_date=?, status=?, scope_id=?, currentTask_id=?, description=?, executor_id=?, target=? where id=? and version=?
2017-06-08 21:48:58,863 [main] DEBUG o.h.SQL - call next value for hibernate_sequence
2017-06-08 21:48:58,864 [main] DEBUG o.h.SQL - call next value for z_revisioninfo_SEQ
2017-06-08 21:48:58,881 [main] DEBUG o.h.SQL - insert into z_revisioninfo (uuid, lead, transition_comment, transition_name, user_id, type_disc, id) values (?, ?, ?, ?, ?, 'RevisionInfo', ?)
2017-06-08 21:48:58,884 [main] DEBUG o.h.SQL - insert into z_revisionentity (revisionInfo_id, timestamp, id) values (?, ?, ?)
2017-06-08 21:48:58,886 [main] DEBUG o.h.SQL - insert into Z_AUD_Task (REVTYPE, uuid, created_date, emailnotification, modified_date, status, amount, description, iterations, letter, running, target, title, creator_id, scope_id, country_id, currentTaskType_id, details_id, responsible_id, id, REV) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
2017-06-08 21:48:58,891 [main] DEBUG o.h.SQL - insert into Z_AUD_operationdetails (REVTYPE, uuid, details, operation_id, id, REV) values (?, ?, ?, ?, ?, ?)
2017-06-08 21:48:58,893 [main] DEBUG o.h.SQL - insert into Z_AUD_operationdetails (REVTYPE, uuid, details, operation_id, id, REV) values (?, ?, ?, ?, ?, ?)
2017-06-08 21:48:58,894 [main] DEBUG o.h.SQL - insert into Z_AUD_operation (REVTYPE, uuid, created_date, emailnotification, modified_date, status, description, target, creator_id, scope_id, currentTask_id, executor_id, id, REV) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
Please let me know if you need anything more. |