We are using the @FilterJoinTable-Annotation for Filtering @ManyToMany-Entities.
Code:
...
@ManyToMany(targetEntity = StructureNodeVO.class)
@JoinTable(name = "editor_einstiegsordner", joinColumns = { @JoinColumn(name = "usr", referencedColumnName = "id"),
@JoinColumn(name = "cusid", referencedColumnName = "cusid", nullable = false) }, inverseJoinColumns = @JoinColumn(name = "gruppe_ordner"))
@FilterJoinTables({ @FilterJoinTable(name = "archiv"), @FilterJoinTable(name = "owner") })
@Filters({ @Filter(name = "archiv"), @Filter(name = "owner") })
private Set<GruppeOrdnerVO> gruppeneditorEinstiegsordner = new HashSet<GruppeOrdnerVO>();
...
We defined the Filter's for "archiv" and "owner" in a separate Class.
Code:
...
@org.hibernate.annotations.FilterDef(name = "archiv", defaultCondition = "archiv = 'false'"),
@org.hibernate.annotations.FilterDef(name = "owner", defaultCondition = "cusid = :ownerid", parameters = @org.hibernate.annotations.ParamDef(
name = "ownerid", type = "long")),
...
While using hibernate 3.6 everything works as expected. Since we upgraded to hibernate 4.2.1, we had to add the defaultCondition of the Filter-Definition to the FilterJoinTable-Annotation:
@FilterJoinTables({ @FilterJoinTable(name = "archiv"
, condition="archiv = 'false'"), @FilterJoinTable(name = "owner"
, condition="cusid = :ownerid") })
The cause of this seems to be HHH-2394. There was a little adjustment to the
org.hibernate.cfg.annotations.CollectionBinder.bindFilters(boolean)-Method, according the @FilterJoinTable-condition is written into filter-collection.
The relevant commit is https://github.com/hibernate/hibernate-orm/commit/05dcc209ae44dfa1fc39da67463a603d44199ba9#hibernate-core/src/main/java/org/hibernate/cfg/annotations/CollectionBinder.java, Line 833
Has anybody an explantaion why this adjustments where necessary? Or is this a bug (it seems to be a bug, but I am not sure)?