8 Replies Latest reply on Aug 13, 2007 5:03 PM by Alex Grönholm

    PersistenceContext injection in Seam 2.0beta1

    Alex Grönholm Novice

      Trying to inject a Hibernate Session with @PersistenceContext fails:


      java.lang.ClassCastException: $Proxy1497 cannot be cast to javax.persistence.EntityManager

      The reason for this was pretty obvious once I took a look at the code of org.jboss.seam.intercept.SessionBeanInterceptor:
      ...
       //wrap any @PersistenceContext attributes in our proxy
       for ( BijectedAttribute ba: getComponent().getPersistenceContextAttributes() )
       {
       EntityManager entityManager = (EntityManager) ba.get(bean);
       if ( ! (entityManager instanceof EntityManagerProxy ) )
       {
       ba.set( bean, new EntityManagerProxy(entityManager) );
       }
       }
      ...
      

      Apparently it doesn't even look at the field type, and always assumes that I want to inject an EntityManager. Even if I do inject an EntityManager, then #getDelegate() won't give me a Session, as it would without Seam. How the heck do I directly inject a Hibernate Session??