|
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:
@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:
@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:
Filter enableFilter = session.enableFilter( "aliveOnly" );
enableFilter.setParameter( "aliveTimestamp", Timestamp.valueOf( "9999-12-31 00:00:00" ) );
enableFilter.validate();
and execute the following query:
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:
[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.
|