[jboss-user] [JBoss Seam] - How to create hibernate criteria

knuwu do-not-reply at jboss.com
Tue Jun 26 15:48:27 EDT 2007


Hi

I like to create a hibernate criteria instead a normal query.


  |  @PersistenceContext(type=PersistenceContextType.EXTENDED)
  |  private EntityManager em;
  | 
  |   public void search()
  |   {
  |     log.info("Get all users");
  |     
  |     Criteria c = ((Session)em.getDelegate()).createCriteria(User.class)
  |       .setMaxResults(this.pageSize)
  |       .addOrder(Order.asc("userid"));
  |     
  |     if (user.getUserid() != null && user.getUserid().length() > 0) {
  |       c.add(Restrictions.like("userid", user.getUserid() + "%"));
  |     }
  |     
  |     this.userList = c.list();
  | 

I always get an ClassCastException for the Session.


  | Caused by: java.lang.ClassCastException: org.hibernate.ejb.EntityManagerImpl
  | 	at com.swisscom.seat.modules.base.admin.UserManagerBean.search(UserManagerBean.java:132)
  | 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  | 	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
  | 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
  | 	at java.lang.reflect.Method.invoke(Method.java:585)
  | 	at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:112)
  | 	at org.jboss.ejb3.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:166)
  | 	at org.jboss.seam.intercept.EJBInvocationContext.proceed(EJBInvocationContext.java:37)
  | 	at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:57)
  | ...
  | ...
  | 

How can one get the Hiberate Session to create a criteria?

Im using a standard seam 1.2.1 configuration generated by seam-gen.

Thanks!

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4057865#4057865

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4057865



More information about the jboss-user mailing list