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 @Name("searchParameters") | 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; | | @PostConstruct | public void setSession() | { | HibernateUtil.setSession(session); | } | | @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() | { | try | { | DetachedCriteria searchCriteria = searchParameters.getSearchCriteria(); | Criteria crit = searchCriteria.getExecutableCriteria(session); | crit.setMaxResults(100); | returnprinces = crit.list(); | } | | if (returnprinces.size()>0) | { | return "found"; | } | else | { | return "notfound"; | } | | catch ( Exception e ) | {/** | * TODO:Implement error handeling when looking for princes in the future :) | */ | e.printStackTrace(); | 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? View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3917922#3917922 Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3917922 ------------------------------------------------------- This SF.net email is sponsored by: Splunk Inc. Do you grep through log files for problems? Stop! Download the new AJAX search engine that makes searching your log files as easy as surfing the web. DOWNLOAD SPLUNK! http://sel.as-us.falkag.net/sel?cmd=lnk&kid=103432&bid=230486&dat=121642 _______________________________________________ JBoss-user mailing list JBoss-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jboss-user