Hibernate version:
2.1.7c
I have to classes, A and B that both implement interface C. What I am trying to do is query for any instances of A or B that match a criteria.
If I use the criteria object and create my expression like so
Code:
Criteria criteria = session.createCriteria(C.class);
criteria.add(Expression.eq("lastName", lastNameParam);
List results = criteria.list();
Everything works fine and I get back a list that contains both A and B objects.
The problem is that I have multiple search fields to work with. In this situation they have a form they can fill out with search criteria (Last Name, First Name, Address, City, etc....) The more they populate, the more restrictive the search gets. Becuase the fields the populate is going to change so much from user to user, I wanted to use the "Example" object to do my queries becuase it gives me a clean way to implement this.
With the example object my code becomes.
Code:
Criteria criteria = session.createCriteria(C.class);
Example example = Example.create(exampleObject);
criteria.add(example);
List results = criteria.list();
When I try to run this I get the following error
Code:
net.sf.hibernate.PropertyAccessException: exception getting property value with CGLIB (set hibernate.cglib.use_reflection_optimizer=false for more info) getter of tapestry.demo.domain.A.?
Now the specific class that shows the error changes depending on which concrete implementation is passed to the example object. In the situation above "exampleObject" is of type B. If "exampleObject" was of type A, the class B would throw the error.
Looking through the stack trace it seems to be caused by a ClassCastException getting thrown beneath the hood.
Is there anyway to make this type of Example query work with a polymorphic mapping? Or am I stuck going back to the
Code:
criteria.add(Expression.eq("lastName", lastNameParam);
way of doing things?
I am really trying to avoid the if/else tree that this way requires. (I have to if/else for each paramter of the example object to see if it's null or not and then add it to the criteria as needed).
Any help would be appreciated.