-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: HibernateException: No such filter configured !
PostPosted: Fri Jun 26, 2009 10:14 am 
Newbie

Joined: Fri Apr 10, 2009 6:25 am
Posts: 5
Dear team,

Towards http://www.next-presso.fr/2008/10/how-to-use-hibernate-filters-in-seam/lang/en and refering some related posts. I tried to use the hibernate filters with seam. However it thrown org.hibernate.HibernateException: No such filter configured [createdDateWorklogFilter]

Code:
WorkLog.java
Code:
import org.hibernate.annotations.*;
@Entity
@Table(name = "WORK_LOG", schema = "dbo", catalog = "PORTALNEW")
@FilterDef (name = "createdDateWorklogFilter", parameters = {
    @ParamDef (name = "from", type = "java.util.Date"),
    @ParamDef (name = "to", type = "java.util.Date")
})
@Filters( {
   @Filter (name = "createdDateWorklogFilter", condition = "CREATED_DATE >= :from and CREATED_DATE <= :to")
})
public class WorkLog implements java.io.Serializable {
.
.
   @Temporal(TemporalType.TIMESTAMP)
   @Column(name = "CREATED_DATE", nullable = false, length = 23)
   @NotNull
   public Date getCreatedDate() {
.
.
}


Issues.java
Code:
@Entity
@Table(name = "ISSUES", schema = "dbo", catalog = "PORTALNEW",
   uniqueConstraints = {@UniqueConstraint(columnNames={"ISSUE_ID"})})
public class Issues implements java.io.Serializable{
.
.
   @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "issues")
   @OrderBy("createdDate DESC")
   @Filter (name = "createdDateWorklogFilter", condition = "CREATED_DATE >= :from and CREATED_DATE <= :to")
   public Set<WorkLog> getWorkLogs() {
.
.}


IssuesList.java
Code:
@Name("issuesList")
public class IssuesList extends EntityQuery<Issues> {
.
.
   @SuppressWarnings("unchecked")
   public List<Issues> fetchIssuesWorked(){
      
       List<Issues> issuesWorked = null;
      
       try {
         
          System.out.println("Date: from:"+getFromStartDate()+" to:"+getToStartDate());
          Session session=(Session) entityManager.getDelegate();
//          Session session = hibernateEntityManager.getSession();
          Filter eventfilter = session.enableFilter("createdDateWorklogFilter");
                eventfilter.setParameter("from", utility.minOfDate(this.getFromStartDate()));
                eventfilter.setParameter("to", utility.maxOfDate(this.getToStartDate()));
          issuesWorked = session.createQuery("from Issues").list();
          session.disableFilter("createdDateWorklogFilter");
      } catch (Exception e) {
         System.out.println("@IssuesList.fetchIssuesWorked(): "+e);
      }      
       return issuesWorked;
    }
.
.
}


component.xml

Code:
   <persistence:filter name="WorkLogFilter" enabled="#{!(empty issuesList.toStartDate and empty issuesList.fromStartDate)}">
         <persistence:name>createdDateWorklogFilter</persistence:name>
         <persistence:parameters>
            <key>from</key> <value>#{issuesList.fromStartDate}</value>
            <key>to</key> <value>#{issuesList.toStartDate}</value>
         </persistence:parameters>
   </persistence:filter>

<persistence:managed-persistence-context auto-create="true" name="entityManager"
  entity-manager-factory="#{PortalEntityManagerFactory}">
         <persistence:filters>
            <value>#{WorkLogFilter}</value>
         </persistence:filters>
  </persistence:managed-persistence-context>


Where issuesList.fromStartDate and issuesList.toStartDate are java.util.Date with getter & setters. issuesList is a seam Entity implementing EntityQuery.

Please assist, with what I'm missing. Thank you in advance!


Top
 Profile  
 
 Post subject: Re: HibernateException: No such filter configured !
PostPosted: Mon Jun 29, 2009 5:31 pm 
Newbie

Joined: Mon Jun 29, 2009 5:20 pm
Posts: 1
I see two problems in your code.

1) your @filterdef is after the @entity keyword. I don't think this is the cause of your error but as @filterdef belongs to a larger scope than @Entity it is quite strange to see it here

2) This second point is probably the origin of your bug. Again, you define your filter in one entity but you also use it in another entity. the second entity cannot see the filter. To correct this do as I wrote in my article (http://www.next-presso.fr/2008/10/how-to-use-hibernate-filters-in-seam/). Put your @filterdef at the package level in the "package-info.java" file. After that you'll be able to use it in all the entities of the package.


Antoine Sabot-Durand
---------------------------
http://www.next-presso.fr


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.