[jboss-user] [JBoss Seam] - PersistenceContext injection in Seam 2.0beta1

alexg79 do-not-reply at jboss.com
Sat Aug 11 10:06:08 EDT 2007


Trying to inject a Hibernate Session with @PersistenceContext fails:
anonymous wrote : 
  | 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??

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

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



More information about the jboss-user mailing list