Solved

Hibernate filters

Posted on 2006-10-19
3
660 Views
Last Modified: 2013-11-24
I have the following:
<hibernate-mapping>
    .
    .
    <class name="Persons" table="persons">
        <cache usage="read-only"/>
        <id name="personID" column="ID"/>
        <property name="firstName" column="First_Name"/>
        <property name="middleName" column="Middle_Name"/>
        <property name="lastName" column="Last_Name"/>
        <property name="inActive" column="Deleted_Flag" type="java.lang.Character"/>
        <filter name="activePersons" condition=":ActivePerson.compareTo(inActive) != 0"/>
    </class>
    <filter-def name="activePersons">
        <filter-param name="ActivePerson" type="java.lang.Character"/>
    </filter-def>
</hibernate-mapping>
_______________________________________________________________________________________
public class Persons {
    private int personID;
    private String firstName;
    private String middleName;
    private String lastName;
    private Character inActive;
   
    .
    .
    private Character isInActive() {
        return inActive;
    }

    private void setInActive(Character active) {
        this.inActive = active;
    }
_______________________________________________________________________________________
private void viewSource(int sc) {
        Transaction tx = null;
        Session session = SessionFactoryManager.getCurrentSession(RMSUtility.ROS_DB);
        Criteria criteria;



        tx = session.beginTransaction();
        Filter filter = session.enableFilter("activePersons");
        filter.setParameter("ActivePerson", new Character('Y'));

        criteria = session.createCriteria(Persons.class);
        criteria.add(Restrictions.eq("personID",sc));

        List list = criteria.list();
        Iterator iter = list.iterator();
        if(iter.hasNext())
            System.out.println(iter.next().toString());

        tx.commit();
    }
_________________________________________________________________________________

And I am getting the following error everytime I try to create a List:

Exception in thread "main" java.lang.InternalError: Unable to locate type for filter parameter
      at org.hibernate.impl.SessionImpl.getFilterParameterType(SessionImpl.java:1050)
      at org.hibernate.engine.QueryParameters.processFilters(QueryParameters.java:387)
      at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1530)
      at org.hibernate.loader.Loader.doQuery(Loader.java:661)
      at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
      at org.hibernate.loader.Loader.doList(Loader.java:2145)
      at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2029)
      at org.hibernate.loader.Loader.list(Loader.java:2024)
      at org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:94)
      at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1533)
      at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:283)
      at rms.utility.EventManager.viewSource(EventManager.java:161)
      at rms.utility.EventManager.main(EventManager.java:105)
0
Comment
Question by:rufassa
3 Comments
 
LVL 8

Accepted Solution

by:
reach2piyush earned 500 total points
Comment Utility
Instead of java.lang.Character try using the simple char type

Java - char
Hibernate - character
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now