Audited with index

Description

I have the following two entities:

@Audited
@Table(
name = "t_parent"
)
@Entity
public class Parent {

@OneToMany(mappedBy = "parent", cascade = CascadeType.ALL, orphanRemoval = true)
private List<Child> children;

}

@Audited
@Table(
name = "t_child",
indexes = {
@Index(columnList = "parent_id")
}
)
@Entity
public class Child {

@ManyToOne(optional = false)
@JoinColumn(name = "parent_id")
private Parent parent;

}
When I query the log of a parant of data, it is very slow, because the child's log (more than ten million data) has no index in the table. Could you add annotations like AuditIndexs or Audited#indexes()?

Activity

Show:

Chris Cranford July 29, 2019 at 1:30 PM

There are a couple problems when creating indexes for audited tables and the main problem is column order.

Envers gathers all mapping metadata from ORM and generates a series of HBM XML mappings. The problem is this format doesn’t support dictating order of columns per index so you can easily run into a situation for any multi-column index that the order of the columns in the generated audit index likely may not appear in the same order as that of the main table, which can have performance degradation problems if built incorrectly.

Is there a reason why doing this manually is a problem?

We could investigate using the Auxiliary Database Objects mapping and attempt to define the index using the create and delete modes of operation when we build the HBM XML mapping. The one last standing concern will be that which is pointed out in which is handling naming of indexes since they must be uniquely named across databases.

Details

Assignee

Reporter

Labels

Components

Priority

Created July 27, 2019 at 9:03 AM
Updated July 29, 2019 at 1:30 PM