Is it possible to get the entity manager from a servlet? I am using JBoss-Seam
CVS and running it on Tomcat under the ejb3 container. I am trying to integrate
support with PayPal and have written a servlet to catch the call from paypal.
In that method I want to get access to my PayPalTransaction object to persist a
new object/record to the database.
What I tried:
UserTransaction utx = Transactions.getUserTransaction();
| utx.begin();
| try
| {
| EntityManager entityManager = (EntityManager)
|
Naming.getInitialContext().lookup("java:/EntityManagers/entityManager");
|
I also tried "java:/entityManager" and just "entityManager"
The lookup is failing.
Error I got:
javax.naming.NameNotFoundException: EntityManagers not bound
| at org.jnp.server.NamingServer.getBinding(NamingServer.java:529)
| at org.jnp.server.NamingServer.getBinding(NamingServer.java:537)
| at org.jnp.server.NamingServer.getObject(NamingServer.java:543)
| at org.jnp.server.NamingServer.lookup(NamingServer.java:267)
| at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:625)
| at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:587)
| at javax.naming.InitialContext.lookup(InitialContext.java:351)
|
Persistence.xml:
| <persistence>
| <persistence-unit name="entityManager"
transaction-type="RESOURCE_LOCAL">
| <provider>org.hibernate.ejb.HibernatePersistence</provider>
| <jta-data-source>java:/bethanyDatasource</jta-data-source>
| <properties>
| <property name="hibernate.dialect"
| value="org.hibernate.dialect.PostgreSQLDialect"
/>
| <property
name="connection.release_mode">after_statement</property>
| <property
name="hibernate.default_schema">public</property>
| <property
name="hibernate.transaction.manager_lookup_class"
|
value="org.hibernate.transaction.JBossTransactionManagerLookup"/>
| <property
name="hibernate.transaction.flush_before_completion" value="true"/>
| <property name="hibernate.show_sql" value="true"/>
| <property
name="hibernate.query.substitutions"></property>
| <property name="jboss.entity.manager.factory.jndi.name"
| value="java:/bethanyEntityManagerFactory"/>
| </properties>
| </persistence-unit>
| </persistence>
|
jboss-beans.xml:
<?xml version="1.0" encoding="UTF-8"?>
|
| <deployment xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
| xsi:schemaLocation="urn:jboss:bean-deployer bean-deployer_1_0.xsd"
| xmlns="urn:jboss:bean-deployer">
|
| <bean name="bethanyDatasourceBootstrap"
| class="org.jboss.resource.adapter.jdbc.local.LocalTxDataSource">
| <property name="driverClass">org.postgresql.Driver</property>
| <property
name="connectionURL">jdbc:postgresql://localhost/bethany</property>
| <property name="userName">bethany</property>
| <property name="password">xxx</property>
| <property name="jndiName">java:/bethanyDatasource</property>
| <property name="minSize">0</property>
| <property name="maxSize">10</property>
| <property name="blockingTimeout">1000</property>
| <property name="idleTimeout">100000</property>
| <property name="transactionManager"><inject
bean="TransactionManager" /></property>
| <property name="cachedConnectionManager"><inject
bean="CachedConnectionManager" /></property>
| <property name="initialContextProperties"><inject
bean="InitialContextProperties" /></property>
| </bean>
|
| <bean name="bethanyDatasource" class="java.lang.Object">
| <constructor factoryMethod="getDatasource">
| <factory bean="bethanyDatasourceBootstrap" />
| </constructor>
| </bean>
|
| </deployment>
Is it possible to do this outside of the faces context?
Thanks,
Andrew
View the original post :
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3941453#3941453
Reply to the post :
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3941453
-------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
JBoss-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jboss-user