2008/11/11, David Blevins <[EMAIL PROTECTED]>:
>
> On Nov 11, 2008, at 11:00 AM, Carlos MacLeod wrote:
>
>> Hi,
>>
>> Is there a way to inject the UserTransaction without a JNDI lookup ?
>> In Glassfish i simple di:
>>
>> @Resource
>> private UserTransaction utx;
>>
>>
>> And the transaction is injected. How can i configure the openejb so it
>> can work ?
>
> Hi Carlos,
>
> That style of injection should work just fine for any servlet or ejb.
> If it's an ejb the ejb should be annotated with
> @TransactionManagement(BEAN).
>
Hi David,
I never used this annotation before ( Since Sun's Glassfish does not
require it in order to do the injection ), but i tried and still not
working.
> If you have any details on which kind of component you are using it in
> and what Tomcat version, that'd be great.
>
> -David
>
>
I am using
- apache-tomcat-6.0.16 ( bundled in netbeans, with the java agent
loaded by -javaagent option in jvm options )
- OpenEJB 3.1 ( downloaded as .war )
- JSF 1.2
- OpenJPA ( Bundled in openejb )
- JavaDB
- Java 1.6.0_04 64 bits
- Suse Linux 10.2 X86_64
My controller bean relevant code( From Netbeans JSF CRUDE )
@TransactionManagement(TransactionManagementType.BEAN)
public class CategoriaController {
@Resource
private UserTransaction utx = null;
@PersistenceUnit(unitName = "BundaPU")
private EntityManagerFactory emf = null;
public EntityManager getEntityManager() {
return emf.createEntityManager();
}
...
...
}
The persistence Unit:
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";>
org.apache.openjpa.persistence.PersistenceProviderImpl
java:openejb/Resource/BundaDS
The JNDI binding in openejb.xml
JdbcDriver org.apache.derby.jdbc.ClientDriver
JdbcUrl jdbc:derby://localhost:1527/testedb
UserName X
Password XX
JtaManaged true
When OpenEJB deploys the application i get the following error ( The
database works fine, the problem only occours when i use
@Resource private Usertransaction utx;
, no matter if i use
@TransactionManagement(TransactionManagementType.BEAN) or not )
2008-11-12 00:40:54,454 - INFO - Configuring enterprise application:
/windows/D/NetBeansProjects/Bunda/build/web
2008-11-12 00:40:54,491 - INFO - Configuring
PersistenceUnit(name=BundaPU,
provider=org.apache.openjpa.persistence.PersistenceProviderImpl)
2008-11-12 00:40:54,492 - INFO - Auto-creating a Resource with id
'BundaDSNonJta' of type 'DataSource for 'BundaPU'.
2008-11-12 00:40:54,492 - INFO - Configuring
Service(id=BundaDSNonJta, type=Resource, provider-id=BundaDS)
2008-11-12 00:40:54,492 - INFO - Creating Resource(id=BundaDSNonJta)
2008-11-12 00:40:54,697 - INFO - Adjusting BundaPU
to 'BundaDS'
2008-11-12 00:40:54,697 - INFO - Adjusting BundaPU
to 'BundaDSNonJta'
2008-11-12 00:40:54,700 - INFO - Enterprise application
"/windows/D/NetBeansProjects/Bunda/build/web" loaded.
2008-11-12 00:40:54,700 - INFO - Assembling app:
/windows/D/NetBeansProjects/Bunda/build/web
2008-11-12 00:40:54,730 - INFO - PersistenceUnit(name=BundaPU,
provider=org.apache.openjpa.persistence.PersistenceProviderImpl)
2008-11-12 00:40:55,147 - INFO - Deployed
Application(path=/windows/D/NetBeansProjects/Bunda/build/web)
2008-11-12 00:40:55,155 - ERROR - Error merging OpenEJB JNDI entries
in to war /Bunda: Exception: null
java.lang.NullPointerException
at java.util.Hashtable.put(Hashtable.java:394)
at
org.apache.catalina.deploy.NamingResources.addResourceEnvRef(NamingResources.java:320)
at
org.apache.openejb.tomcat.catalina.TomcatJndiBuilder.mergeRef(TomcatJndiBuilder.java:416)
at
org.apache.openejb.tomcat.catalina.TomcatJndiBuilder.mergeJndi(TomcatJndiBuilder.java:140)
at
org.apache.openejb.tomcat.catalina.TomcatWebAppBuilder.start(TomcatWebAppBuilder.java:270)
at
org.apache.openejb.tomcat.catalina.GlobalListenerSupport.lifecycleEvent(GlobalListenerSupport.java:58)
at
org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
at
org.apache.catalina.core.StandardContext.start(StandardContext.java:4252)
at
org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:791)
at
org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:525)
at
org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:626)
at
org.apache.catalina.startup.HostConfig.deployDescriptors(HostConfig.java:553)
at
org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:488)
at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1147)
at
org.apache.catalina