Hello
I have a problem with the use of @Filter and @FilterDef. I tried a lot of possibilities but none of them are working. I don't get any errors, the filter is just not filtering, I still receive all the records.
I have the Entity Rubriek, that has one or more SubRubrieken, and each SubRubriek is linked to a LijstStatus that is on his turn linked to a List. What I want is all the Rubrieken where ListID=65.
The problem is that I don't know where I have to put the @Filter-annotation. Do I have to put them on each level or not? And do I have to put them on top of the class of in the class itself? This is what I have for the moment:
RubriekDaoHibernateImpl.java
Code:
@Name("rubriekDao")
public List<Rubriek> getAlleRubrieken(String rol) {
   Session session=(Session) entityManager.getDelegate(); 
   session.enableFilter("f_lijststatus_lijstid").setParameter("lijstid", new Long(65));
   List<Rubriek> results = entityManager.createQuery("from Rubriek where actief = 1 and (rol is null or instr(rol,:rol) > 0) order by rang").setParameter("rol",rol).getResultList();
      
   session.disableFilter("f_lijststatus_lijstid");
   return results;
}
package-info.java
Code:
@FilterDef(name="f_lijststatus_lijstid", parameters=@ParamDef(name="lijstid",type="long"))
package vo.cjsm.ccinc.entity;
import org.hibernate.annotations.FilterDef;
import org.hibernate.annotations.ParamDef;
Rubriek.java
Code:
@Entity
@Table
public class Rubriek extends AbstractStructure{
   ...
  @OneToMany(mappedBy="rubriek")
  public List<SubRubriek> getSubRubrieken() {
      if (subRubrieken == null)
         subRubrieken = new ArrayList<SubRubriek>();
      return subRubrieken;
   }
}
SubRubriek.java
Code:
@Entity
@Table
public class SubRubriek extends AbstractStructure {
   ...
   @OneToMany(mappedBy="subRubriek",fetch=FetchType.LAZY)
   @Filter(name="f_lijststatus_lijstid", condition=":lijstid = lijst.lijstID")
   public List<LijstStatus> getLijstStatussen() {
      if (lijstStatussen == null)
         lijstStatussen = new ArrayList<LijstStatus>();
      return lijstStatussen;
   }
}
LijstStatus.java
Code:
@Entity
@Table
@Filter(name="f_lijststatus_lijstid", condition=":lijstid = lijst.lijstID")
public class LijstStatus extends AbstractEntity {
   ...
   @ManyToOne
   @JoinColumn(name="lijstID")
   @NotNull
   public Lijst getLijst() {
      return lijst;
   }
}
Lijst.java
Code:
@Entity
@Table
@Filter(name="f_lijststatus_lijstid", condition=":lijstid = lijstID")
public class Lijst extends AbstractEntity {
   ...
   @Id
   @SequenceGenerator(name="generator",sequenceName="LIJST_SEQ")
   @GeneratedValue(strategy=GenerationType.SEQUENCE,generator="generator")
   public Long getLijstID() {
      return lijstID;
   }
}
Thanks in advance!
barbara