-
1. Re: PersistenceContext injection in Seam 2.0beta1
pmuir Aug 11, 2007 10:14 AM (in response to alexg79)@PersistenceContext is part of JPA, why would it be able to inject a Hibernate Session.
Try@In Session session;
-
2. Re: PersistenceContext injection in Seam 2.0beta1
alexg79 Aug 11, 2007 10:40 AM (in response to alexg79)It works perfectly well without the Seam interceptors messing with it. Try it and you'll see.
-
3. Re: PersistenceContext injection in Seam 2.0beta1
alexg79 Aug 11, 2007 10:52 AM (in response to alexg79)@PersistenceContext is part of JPA, why would it be able to inject a Hibernate Session.
Further proof here:
http://docs.jboss.com/ejb3/app-server/reference/build/reference/en/html/hibernate.html
4.2. Injection Hibernate Session and SessionFactory
You can inject a org.hibernate.Session and org.hibernate.SessionFactory directly into your EJBs just as you can do with EntityManagers and EntityManagerFactorys. The behavior of a Session is just the same as the behavior of an injected EntityManager. The application server controls the lifecycle of the Session so that you do not have to open, flush, or close the session. Extended persistence contexts also work with injected Hibernate Sessions.
import org.hibernate.Session;
import org.hibernate.SessionFactory;
@Stateful public class MyStatefulBean ... {
@PersistenceContext(unitName="crm") Session session1;
@PersistenceContext(unitName="crm2", type=EXTENDED) Session extendedpc;
@PersistenceUnit(unitName="crm") SessionFactory factory;
} -
4. Re: PersistenceContext injection in Seam 2.0beta1
pmuir Aug 11, 2007 10:58 AM (in response to alexg79)Looking at the JPA spec, there is no reference to being able to use @PersistenceContext to inject the delegate (http://java.sun.com/javaee/5/docs/api/javax/persistence/PersistenceContext.html) so I'm guessing this is a Hibernate extension. We should probably support it, can you raise an issue in JIRA? Thanks!
-
5. Re: PersistenceContext injection in Seam 2.0beta1
alexg79 Aug 12, 2007 12:53 PM (in response to alexg79)JIRA issue created:
http://jira.jboss.org/jira/browse/JBSEAM-1787 -
6. Re: PersistenceContext injection in Seam 2.0beta1
alexg79 Aug 13, 2007 3:54 PM (in response to alexg79)Alright, I picked up the latest CVS version and Session injection indeed seems to work now.
However, while testing I also noted that getDelegate() from a proxied EntityManager (@PersistenceContext(type = EXTENDED)) throws a NPE.
Is this supposed to work? -
7. Re: PersistenceContext injection in Seam 2.0beta1
pmuir Aug 13, 2007 4:52 PM (in response to alexg79)Yes, I can see this to. Can you file a JIRA issue please? Thanks!
-
8. Re: PersistenceContext injection in Seam 2.0beta1
alexg79 Aug 13, 2007 5:03 PM (in response to alexg79)