An internal Envers Query on historic data triggers a QueryException when navigating a ternary association mapped as "map" with an entity as key and a value object as value mapped as composite-element. The following example might help to understand the problem: Assume the collection property is: @Audited public class Category { [...] private Map<Item, Value> categoryItem = new HashMap<>(); [...] } Where Item is an entity and Value is a value object with several properties. The XML mapping then looks like: <hibernate-mapping package="enverstest.model" default-access="field" > <class name="Category" table="category"> [...] <map name="categoryItem" table="category_item"> <key column="category_id" not-null="true" /> <map-key-many-to-many column="item_id" class="Item"/> <composite-element class="Value" > <property name="number" column="number" /> <property name="text" column="text" /> </composite-element> </map> </class> </hibernate-mapping> The query created by Envers triggering the exception is: select new list(ee_, e_) from category_item_r ee__, enverstest.model.Item_r e__ where ee_.originalId.mapkey_id = e_.originalId.id and ee__.originalId.Category_id = :Category_id and e__.originalId.rev_begin.id <= :revision and ee__.originalId.rev_begin.id <= :revision and ee__.originalId.rev_type != :delrevisiontype and e__.originalId.rev_type != :delrevisiontype and (e_.rev_end.id > :revision or e_.rev_end is null) and (ee_.rev_end.id > :revision or ee_.rev_end is null) When I map the collection using a CompositeUserType, the query works and I can navigate the association (but then I get a problem with nullable properties in the composite user type, because Envers creates a SQL where clause with checks for "property=null" instead of "property is null". Perhaps I should write another bug report for this issue, too?) For a full description see <https://developer.jboss.org/thread/275323> Here I also describe the second problem with nullable properties. The attached tar archive contains a complete test case for both problems. See JUnit test case CategoryTest, first. There are two boolean variables you can set to demonstrate either the "QueryException" or the "nullable property" problem. You will have to modify the mapping document Category.hbm.xml to demonstrate the QueryException problem as by default I have the CompositeUserType workaround enabled. The tar archive also contains a DDL SQL script for the required test database. It should work with a PostgreSQL RDBMS out of the box. You will have to modify persistence.xml for your DB environment. |