A problem occurrs with the following mapping:
@Entity
public class Person {
@Id
@GeneratedValue
private Integer id;
@Audited
private String name;
@Audited
@OneToMany(mappedBy = "person", cascade = CascadeType.ALL)
@OrderColumn(name = "index")
private List<Document> documents;
}
@Entity
public class Document {
@Id
@GeneratedValue
private Integer id;
@Audited
private String contents;
@Audited(targetAuditMode = RelationTargetAuditMode.NOT_AUDITED)
@ManyToOne
@JoinColumn(name = "person_id")
private Person person;
}
It seems that in this case Envers ignores OrderColumn annotation and creates document_AUD table without index column:
create table Document (
id integer generated by default as identity (start with 1),
contents varchar(255),
person_id integer,
index integer,
primary key (id)
)
create table Document_AUD (
id integer not null,
REV integer not null,
REVTYPE tinyint,
contents varchar(255),
person_id integer,
primary key (id, REV)
)
If we add index column manually it will always stay empty.
And then if we try to access documents in Project revision it fails with NPE:
I think it's defenitely a bug.
What are possible work-arounds?
I attached a simple project with hsqldb that reproduces this bug.
|