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.javaCode:
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.javaCode:
@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.javaCode:
@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!