Dynamic filter parameter on OneToMany collection is not bound to elements() expression in WHERE clause

Description

There is a problem with the parameter binding of dynamic filter parameters in case you use a dynamic filter definition on a OneToMany child collection, and add the elements() expression to the WHERE clause.

The filter parameter does not get bound at all.

I have a root entity with a filter definition for the deletion timestamp column, and I also apply this filter on its child entities for their deletion timestamp columns:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 @Entity @Table( name = "`ArticleRevision`" ) @FilterDefs( { @FilterDef( name = "aliveOnly", parameters = { @ParamDef( name = "aliveTimestamp", type = "timestamp" ) }, defaultCondition = "`DeletionTimestamp` = :aliveTimestamp" ) } ) @Filters( { @Filter( name = "aliveOnly", condition = "`DeletionTimestamp` = :aliveTimestamp" ) } ) public class ArticleRevision { @Column( name = "`ArticleID`" ) private Long articleId = null; @Column( name = "`DeletionTimestamp`" ) protected Timestamp deletionTimestamp; @OneToMany( mappedBy = "articleRevision", cascade = CascadeType.ALL, fetch = FetchType.LAZY ) @Filter( name = "aliveOnly" ) private Set< ArticleTrading > articleTradings = new HashSet< ArticleTrading >(); }

This is one of the child entites:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 @Entity @Table( name = "`ArticleTrading`" ) public class ArticleTrading { @ManyToOne( fetch = FetchType.LAZY ) @JoinColumn( name = "`ArticleRevisionID`", nullable = false ) private ArticleRevision articleRevision = null; @Column( name = "`PartyID`" ) private long partyId = 0; @Column( name = "`Classifier`" ) private String classifier = null; @Column( name = "`DeletionTimestamp`" ) protected Timestamp deletionTimestamp; }

Now if I enable the filter in the session:

1 2 3 Filter enableFilter = session.enableFilter( "aliveOnly" ); enableFilter.setParameter( "aliveTimestamp", Timestamp.valueOf( "9999-12-31 00:00:00" ) ); enableFilter.validate();

and execute the following query:

1 2 UPDATE ArticleRevision te SET deletionTimestamp = 2015-09-18 18:27:34.49, deletionUserId = 3 WHERE id IN ( [11489] ) AND NOT EXISTS elements ( te.articleTradings )

the query will result in the following SQL:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 [SQL] update [ArticleRevision] set [DeletionTimestamp]=?, [DeletionUserID]=? where [DeletionTimestamp] = ? and ( [ID] in ( ? ) ) and not (exists (select articletra1_.[ArticleRevisionID] from [ArticleTrading] articletra1_ where [ArticleRevision].[ID]=articletra1_.[ArticleRevisionID] and articletra1_.[DeletionTimestamp] = :aliveOnly.aliveTimestamp))

As you can see the dynamic filter parameter does not get bound.

Please advise if I am doing something wrong, or point me to the proper class where I can start debugging.

Environment

None

Status

Assignee

Unassigned

Reporter

Markus

Fix versions

None

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

4.3.11
4.2.20
5.2.2

Priority

Blocker
Configure