-
1. Re: Seam-managed persistence context on Open EJB
chawax Mar 19, 2009 9:52 AM (in response to chawax)I had a response by David Blevins (OpenEJB founder) on OpenEJB Users list :
In the current releases there's no global JNDI name for EntityManagerFactory instances. In the trunk version (3.1.1) there is work on that might help.
In the meantime, do you know if Seam can lookup from an EJB's or Servlet's java:comp namespace? If that works, you could add an @PersistenceUnit ref (or equivalent xml) somewhere.I have no idea about the question he asks about Seam and java:comp ... Does anyone understand ?
And is there an other way to configure Seam-managed persistence context, with no need of JNDI to get entity manager factory ?
-
2. Re: Seam-managed persistence context on Open EJB
swd847 Mar 19, 2009 11:43 AM (in response to chawax)I have used a hack to get around a similar problem the early jboss 5 version have. It is documented here. Basically you inject the EntityManagerFactory into and EJB and expose it to an el expression. Not as good as a JNDI binding but it works.
-
3. Re: Seam-managed persistence context on Open EJB
chawax Mar 19, 2009 11:52 AM (in response to chawax)Thanks, I will give it a try.
Other thing I tried (saw this in an example for Glassfish) is the following in components.xml :
<persistence:entity-manager-factory name="entityManagerFactory" persistence-unit-name="t4Seam" /> <persistence:managed-persistence-context name="emanager" auto-create="true" entity-manager-factory="#{entityManagerFactory}" />
And this in persistence.xml :
<persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd" version="1.0"> <persistence-unit name="t4Seam"> <provider>org.hibernate.ejb.HibernatePersistence</provider> <jta-data-source>java:/jdbc/t4Seam</jta-data-source> <mapping-file>META-INF/orm-utils.xml</mapping-file> <properties> <property name="hibernate.hbm2ddl.auto" value="update"/> <property name="hibernate.show_sql" value="false"/> </properties> </persistence-unit> </persistence>
It looked pretty good for me, but I have the following stack trace :
WARNING: Found unrecognized persistence provider "org.hibernate.ejb.HibernatePersistence" in place of OpenJPA provider. This provider's properties will not be used. FATAL - Could not find datasource: java:/jdbc/t4Seam javax.naming.NameNotFoundException: Name "java:/jdbc/t4Seam" not found. at org.apache.openejb.core.ivm.naming.IvmContext.federate(IvmContext.java:172) at org.apache.openejb.core.ivm.naming.IvmContext.lookup(IvmContext.java:129) at javax.naming.InitialContext.lookup(InitialContext.java:392) at org.hibernate.connection.DatasourceConnectionProvider.configure(DatasourceConnectionProvider.java:52) at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:124) at org.hibernate.ejb.InjectionSettingsFactory.createConnectionProvider(InjectionSettingsFactory.java:29) at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:62) at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2073) at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1298) at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:859) at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:669) at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:126) at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:52) at org.jboss.seam.persistence.EntityManagerFactory.createEntityManagerFactory(EntityManagerFactory.java:85) at org.jboss.seam.persistence.EntityManagerFactory.startup(EntityManagerFactory.java:50) 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:597) at org.jboss.seam.util.Reflections.invoke(Reflections.java:22) at org.jboss.seam.util.Reflections.invokeAndWrap(Reflections.java:144) at org.jboss.seam.Component.callComponentMethod(Component.java:2219) at org.jboss.seam.Component.callCreateMethod(Component.java:2134) at org.jboss.seam.Component.newInstance(Component.java:2094) at org.jboss.seam.contexts.Contexts.startup(Contexts.java:304) at org.jboss.seam.contexts.Contexts.startup(Contexts.java:278) at org.jboss.seam.contexts.ServletLifecycle.endInitialization(ServletLifecycle.java:112) at org.jboss.seam.init.Initialization.init(Initialization.java:735) at org.jboss.seam.mock.AbstractSeamTest.startSeam(AbstractSeamTest.java:919)
Though it has no problem finding this datasource with the same JNDI name when not using Seam persistence context. I can't understand what happens :(
-
4. Re: Seam-managed persistence context on Open EJB
chawax Mar 19, 2009 12:08 PM (in response to chawax)
Stuart Douglas wrote on Mar 19, 2009 11:43:
I have used a hack to get around a similar problem the early jboss 5 version have. It is documented here. Basically you inject the EntityManagerFactory into and EJB and expose it to an el expression. Not as good as a JNDI binding but it works.I tried it and it looks much better now !
I still have problems, but it deals with transactions this time. I will have to look at how ot use transactions with Seam managed pesistence contexts.
Thanks a lot for your help, I was struggling for this since yesterday !
Regards,
Olivier