QueryException on map associaton when using Envers
Description
Attachments
causes
is fixed by
is followed up by
Activity

Chris Cranford October 19, 2017 at 5:32 AM
Reverted as part of and will follow-up with a fix in HHH-12043.

Chris Cranford September 6, 2017 at 2:17 PMEdited
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".
Moved my comment about this to the related issue. Lets discuss this problem there.

Chris Cranford August 23, 2017 at 3:56 PM
I've tracked down the first problem related to the QueryException
based on not being able to find your rev_type
(aka REVTYPE) field. Based on your mappings, you're using a mapping that the collection metadata producer does not yet support, so we need to look at what changes are necessary to support this.
The root problem here is based on an assumption that the revision type property is mapped the same on both the map-key and map-value. In your use case, the field is mapped as a property on Item
but is mapped as part of the primary key on category_item_AUD
. So when the predicate is added, it uses an incorrect property reference on the Item
side and threfore leads to the QueryException
.
This is shown clearly below:
with the problem being the line
While your use case points out the problem with TwoEntityQueryGenerator
, this is also likely problematic with ThreeEntityQueryGenerator
too.
Once we get past this, I'll look into the null-values problem and likely push that to follow-up JIRA if they're not related.
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:
Where Item is an entity and Value is a value object with several properties.
The XML mapping then looks like:
The query created by Envers triggering the exception is:
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.