diff --git a/documentation/src/main/docbook/devguide/en-US/Envers.xml b/documentation/src/main/docbook/devguide/en-US/Envers.xml index a9df4698db..92e13716dd 100644 --- a/documentation/src/main/docbook/devguide/en-US/Envers.xml +++ b/documentation/src/main/docbook/devguide/en-US/Envers.xml @@ -456,4 +456,88 @@ public class ExampleListener implements RevisionListener { +
+ Mapping exceptions + +
+ + What isn't and will not be supported + + + Bags (the corresponding Java type is List), as they can contain non-unique elements. + The reason is that persisting, for example a bag of String-s, violates a principle + of relational databases: that each table is a set of tuples. In case of bags, + however (which require a join table), if there is a duplicate element, the two + tuples corresponding to the elements will be the same. Hibernate allows this, + however Envers (or more precisely: the database connector) will throw an exception + when trying to persist two identical elements, because of a unique constraint violation. + + + + There are at least two ways out if you need bag semantics: + + + + + + use an indexed collection, with the @IndexColumn annotation, or + + + + + provide a unique id for your elements with the @CollectionId annotation. + + + + +
+ +
+ + What isn't and <emphasis>will</emphasis> be supported + + + + + collections of components + + + + +
+ +
+ + <literal>@OneToMany</literal>+<literal>@JoinColumn</literal> + + + When a collection is mapped using these two annotations, Hibernate doesn't + generate a join table. Envers, however, has to do this, so that when you read the + revisions in which the related entity has changed, you don't get false results. + + + To be able to name the additional join table, there is a special annotation: + @AuditJoinTable, which has similar semantics to JPA's + @JoinTable. + + + + One special case are relations mapped with @OneToMany+@JoinColumn on + the one side, and @ManyToOne+@JoinColumn(insertable=false, updatable=false) + on the many side. + Such relations are in fact bidirectional, but the owning side is the collection (see alse + here). + + + To properly audit such relations with Envers, you can use the @AuditMappedBy annotation. + It enables you to specify the reverse property (using the mappedBy element). In case + of indexed collections, the index column must also be mapped in the referenced entity (using + @Column(insertable=false, updatable=false), and specified using + positionMappedBy. This annotation will affect only the way + Envers works. Please note that the annotation is experimental and may change in the future. + + +
+
+ \ No newline at end of file