1 Reply Latest reply on Jan 17, 2006 12:59 PM by Carolina U.

    DetachedCriteria Query

    Carolina U. Newbie

      Im trying to use a Detached Criteria to make my queries. But I ran into a problem. Here I describe the situation

      I have this class with the parameters to make the search, where I also define a Detached Criteria . that later on I 'll use on my session bean


      public DetachedCriteria getSearchCriteria()
       searchCriteria = DetachedCriteria.forClass(CAROPrince.class);
       if (contains != null)
       searchCriteria.add(Restrictions.ilike("code", contains, MatchMode.ANYWHERE));
      return searchCriteria;

      then I have a bean PrinceSearchAction

      public class PrinceSearchAction implements Serializable, PrinceSearch
       @PersistenceContext(unitName = "princes")
       private Session session;
       public void setSession()
       @In(required = false, create = true)
       private CAROPrince prince;
       @In(required = false, create = true)
       PrinceSearchParameters searchParameters;
       @Out(required = false)
       private List<CAROPrince> returnprinces;
       public String findPrinces()
       DetachedCriteria searchCriteria = searchParameters.getSearchCriteria();
       Criteria crit = searchCriteria.getExecutableCriteria(session);
       returnprinces = crit.list();
       if (returnprinces.size()>0)
       return "found";
       return "notfound";
      catch ( Exception e )
       * TODO:Implement error handeling when looking for princes in the future :)
       return "error";

      WELL, there is always problems when we search for a prince, but my problem is exacly in this line
      -> Criteria crit = searchCriteria.getExecutableCriteria(session);

      And I get the following exception :

      INFO [STDOUT] java.lang.ClassCastException: org.jboss.ejb3.entity.InjectedHibernateSession
      17:31:38,015 INFO [STDOUT] at org.hibernate.criterion.DetachedCriteria.getExecutableCriteria(DetachedCriteria.java:52)
      17:31:38,015 INFO [STDOUT] at py.com.wpg.CooPy.contractManagement.ejb.ContractSearchAction.findContracts(ContractSearchAction.java:103)
      17:31:38,015 INFO [STDOUT] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      17:31:38,015 INFO [STDOUT] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      17:31:38,015 INFO [STDOUT] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      17:31:38,015 INFO [STDOUT] at java.lang.reflect.Method.invoke(Method.java:585)
      17:31:38,015 INFO [STDOUT] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:109)

      What Im doing wrong? Is that a correct way to use the detachedCriteria?