openejb-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jay D. McHugh" <...@jnwd.net>
Subject Re: UserTransaction injection
Date Mon, 17 Nov 2008 20:23:43 GMT
Hello Carlos,

This is a total guess - but, I think that you would have to annotate
your class a being either stateless or statefull to get the container to
'pay attention' to it and inject the transaction.

Jay

Carlos MacLeod wrote:
> 2008/11/11, Carlos MacLeod <carlos.macleod@gmail.com>:
>> 2008/11/11, David Blevins <david.blevins@visi.com>:
>>> 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:
>>
>> <?xml version="1.0" encoding="UTF-8"?>
>> <persistence version="1.0"
>> 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">
>>   <persistence-unit name="BundaPU" transaction-type="JTA">
>>
>> <provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
>>     <jta-data-source>java:openejb/Resource/BundaDS</jta-data-source>
>>     <properties>
>>       <property name="openjpa.jdbc.SynchronizeMappings"
>> value="buildSchema(ForeignKeys=true)"/>
>>     </properties>
>>   </persistence-unit>
>> </persistence>
>>
>>
>> The JNDI binding in openejb.xml
>>
>> <Resource id="BundaDS" type="DataSource">
>> 	JdbcDriver org.apache.derby.jdbc.ClientDriver
>> 	JdbcUrl jdbc:derby://localhost:1527/testedb
>> 	UserName XXXXXXXXXXXXXXXXX
>> 	Password XXXXXXXXXXXXXXXXXX
>> 	JtaManaged true
>> </Resource>
>>
>>
>>
>>
>> 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 <jta-data-source>
>> to 'BundaDS'
>> 2008-11-12 00:40:54,697 - INFO  - Adjusting BundaPU
>> <non-jta-data-source> 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.startup.HostConfig.lifecycleEvent(HostConfig.java:311)
>>         at
>> org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
>>         at
>> org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
>>         at
>> org.apache.catalina.core.StandardHost.start(StandardHost.java:719)
>>         at
>> org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
>>         at
>> org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
>>         at
>> org.apache.catalina.core.StandardService.start(StandardService.java:516)
>>         at
>> org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
>>         at org.apache.catalina.startup.Catalina.start(Catalina.java:578)
>>         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.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
>>         at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
>>
>>
>>
>>
>>
>> and again when a JFS invokes the bean i get the following stack trace:
>>
>>
>>
>>
>> 12/11/2008 00:40:29 org.apache.catalina.core.AprLifecycleListener init
>> INFO: The APR based Apache Tomcat Native library which allows optimal
>> performance in production environments was not found on the
>> java.library.path:
>> /usr/java/jdk1.6.0_04/jre/lib/amd64/server:/usr/java/jdk1.6.0_04/jre/lib/amd64:/usr/java/jdk1.6.0_04/jre/../lib/amd64:/usr/java/packages/lib/amd64:/lib:/usr/lib
>> 12/11/2008 00:40:29 org.apache.coyote.http11.Http11Protocol init
>> INFO: Initializing Coyote HTTP/1.1 on http-8084
>> 12/11/2008 00:40:29 org.apache.catalina.startup.Catalina load
>> INFO: Initialization processed in 11645 ms
>> 12/11/2008 00:40:30 org.apache.catalina.core.StandardService start
>> INFO: Starting service Catalina
>> 12/11/2008 00:40:30 org.apache.catalina.core.StandardEngine start
>> INFO: Starting Servlet Engine: Apache Tomcat/6.0.16
>> 12/11/2008 00:40:55 com.sun.faces.config.ConfigureListener
>> contextInitialized
>> INFO: Initializing Sun's JavaServer Faces implementation
>> (1.2_04-b20-p03) for context '/Bunda'
>> 12/11/2008 00:40:56 org.apache.coyote.http11.Http11Protocol start
>> INFO: Starting Coyote HTTP/1.1 on http-8084
>> 12/11/2008 00:40:56 org.apache.jk.common.ChannelSocket init
>> INFO: JK: ajp13 listening on /0.0.0.0:8009
>> 12/11/2008 00:40:56 org.apache.jk.server.JkMain start
>> INFO: Jk running ID=0 time=0/93  config=null
>> 12/11/2008 00:40:56 org.apache.catalina.startup.Catalina start
>> INFO: Server startup in 26970 ms
>> 12/11/2008 01:05:53 com.sun.faces.application.ApplicationAssociate
>> createAndMaybeStoreManagedBeans
>> SEVERE: JSF1001: Managedbean categoria could not be created.
>> 12/11/2008 01:05:53 com.sun.faces.lifecycle.InvokeApplicationPhase execute
>> WARNING: javax.faces.FacesException:
>> javax.naming.NameNotFoundException: Name utx is not bound in this
>> Context
>> javax.faces.FacesException: javax.faces.FacesException:
>> javax.naming.NameNotFoundException: Name utx is not bound in this
>> Context
>> 	at
>> com.sun.faces.application.ApplicationAssociate.createAndMaybeStoreManagedBeans(ApplicationAssociate.java:537)
>> 	at
>> com.sun.faces.el.ManagedBeanELResolver.getValue(ManagedBeanELResolver.java:82)
>> 	at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:53)
>> 	at
>> com.sun.faces.el.FacesCompositeELResolver.getValue(FacesCompositeELResolver.java:64)
>> 	at org.apache.el.parser.AstIdentifier.getValue(AstIdentifier.java:61)
>> 	at org.apache.el.parser.AstValue.getTarget(AstValue.java:59)
>> 	at org.apache.el.parser.AstValue.invoke(AstValue.java:148)
>> 	at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:276)
>> 	at
>> org.apache.jasper.el.JspMethodExpression.invoke(JspMethodExpression.java:68)
>> 	at
>> javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:77)
>> 	at
>> com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:91)
>> 	at javax.faces.component.UICommand.broadcast(UICommand.java:383)
>> 	at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:447)
>> 	at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:752)
>> 	at
>> com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:97)
>> 	at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:251)
>> 	at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:117)
>> 	at javax.faces.webapp.FacesServlet.service(FacesServlet.java:244)
>> 	at
>> org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
>> 	at
>> org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
>> 	at
>> org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
>> 	at
>> org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
>> 	at
>> org.apache.openejb.tomcat.catalina.OpenEJBValve.invoke(OpenEJBValve.java:45)
>> 	at
>> org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
>> 	at
>> org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
>> 	at
>> org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
>> 	at
>> org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
>> 	at
>> org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
>> 	at
>> org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
>> 	at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
>> 	at java.lang.Thread.run(Thread.java:619)
>> Caused by: javax.faces.FacesException:
>> javax.naming.NameNotFoundException: Name utx is not bound in this
>> Context
>> 	at
>> com.sun.faces.config.ManagedBeanFactoryImpl.newInstance(ManagedBeanFactoryImpl.java:340)
>> 	at
>> com.sun.faces.application.ApplicationAssociate.createAndMaybeStoreManagedBeans(ApplicationAssociate.java:527)
>> 	... 30 more
>> Caused by: javax.naming.NameNotFoundException: Name utx is not bound
>> in this Context
>> 	at org.apache.naming.NamingContext.lookup(NamingContext.java:770)
>> 	at org.apache.naming.NamingContext.lookup(NamingContext.java:140)
>> 	at org.apache.naming.NamingContext.lookup(NamingContext.java:781)
>> 	at org.apache.naming.NamingContext.lookup(NamingContext.java:153)
>> 	at
>> org.apache.catalina.util.DefaultAnnotationProcessor.lookupFieldResource(DefaultAnnotationProcessor.java:203)
>> 	at
>> org.apache.catalina.util.DefaultAnnotationProcessor.processAnnotations(DefaultAnnotationProcessor.java:135)
>> 	at
>> com.sun.faces.vendor.Tomcat6InjectionProvider.inject(Tomcat6InjectionProvider.java:46)
>> 	at
>> com.sun.faces.config.ManagedBeanFactoryImpl.newInstance(ManagedBeanFactoryImpl.java:298)
>> 	... 31 more
>>
>>
>>
>> Thanks by your interest in help me, and sorry, my english is bad...
>>
>> --
>> Best regards,
>> Carlos MacLeod
>>
>> "Java is like violence: if it doesn's solve your problem, you aren't
>> using enough of it"
>>
> 
> Hi guys,
> 
> Seems there are no answer here :-(
> 
> Should i try the developer list ?
> 


Mime
View raw message