You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@geronimo.apache.org by Forrest Xia <fo...@gmail.com> on 2010/01/20 08:10:48 UTC

about daytrader-web-jpa

Hi Donald,

I tried the new assembly of daytrader -- daytrader-web-jpa, and did not get
it work. The console log an error:

2010-01-20 14:08:24,774 ERROR [Log] Error: TradeJPADirect:createQuote --
exception creating Quote
    java.lang.NullPointerException
java.lang.NullPointerException
    at
org.apache.geronimo.samples.daytrader.core.direct.TradeJPADirect.createQuote(TradeJPADirect.java:418)
    at
org.apache.geronimo.samples.daytrader.core.TradeAction.createQuote(TradeAction.java:373)
    at
org.apache.geronimo.samples.daytrader.web.TradeBuildDB.<init>(TradeBuildDB.java:196)
    at
org.apache.geronimo.samples.daytrader.web.TradeConfigServlet.service(TradeConfigServlet.java:411)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:806)
    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:191)
    at
org.apache.geronimo.tomcat.GeronimoStandardContext$SystemMethodValve.invoke(GeronimoStandardContext.java:420)
    at
org.apache.geronimo.tomcat.valve.GeronimoBeforeAfterValve.invoke(GeronimoBeforeAfterValve.java:47)
    at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
    at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
    at
org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:567)
    at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    at
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
    at
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:849)
    at
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
    at
org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:361)
    at org.apache.geronimo.pool.ThreadPool$1.run(ThreadPool.java:214)
    at
org.apache.geronimo.pool.ThreadPool$ContextClassLoaderRunnable.run(ThreadPool.java:344)
    at
java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
    at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
    at java.lang.Thread.run(Thread.java:619)

Then I had a peek at the code, and think this NPE might be caused by
PersistenceContext not injected in TradeJPADirect. Since TradeJPADirect is
not a web container managed object(not servlet or context listener), so the
annotation @PersistenceContext does not work.

I guess daytrader-web-jpa assembly is to demo jpa usage in web module
without session EJB involvement. If we want to demo container-managed entity
manager via this assembly, we shall use @PersistenceContext on servlet or
any web container managed object, then use JNDI lookup to get the entity
manager from container. If we want to demo application-managed entity
manager, we can use @PersistenceUnit to inject an EntityManagerFactory
object in any web container managed object, then use
EntityManagerFactory.createEntityManager() to get entity manager.

Please kindly let me know your thoughts.

Thanks!
Forrest

Re: about daytrader-web-jpa

Posted by Joe Bohn <jo...@earthlink.net>.
FWIW I have a few versions in my sandbox of DayTrader updated for 
blueprint which support JPA direct persistence.  I have both application 
managed (jbohn/daytrader-bp-AppEM) and container managed 
(jbohn/daytrader-bp-CntEM).   Overall the code has been reorganized for 
blueprint but the core function is mostly unchanged ... so they might be 
helpful or at least an interesting comparison.

Joe


Donald Woods wrote:
> I'd prefer the application managed approach, as the Java EE version of
> Daytrader uses container managed.
> 
> Thanks for helping with this.
> 
> 
> -Donald
> 
> 
> On 1/20/10 2:10 AM, Forrest Xia wrote:
>> Hi Donald,
>>
>> I tried the new assembly of daytrader -- daytrader-web-jpa, and did not
>> get it work. The console log an error:
>>
>> 2010-01-20 14:08:24,774 ERROR [Log] Error: TradeJPADirect:createQuote --
>> exception creating Quote
>>     java.lang.NullPointerException
>> java.lang.NullPointerException
>>     at
>> org.apache.geronimo.samples.daytrader.core.direct.TradeJPADirect.createQuote(TradeJPADirect.java:418)
>>     at
>> org.apache.geronimo.samples.daytrader.core.TradeAction.createQuote(TradeAction.java:373)
>>     at
>> org.apache.geronimo.samples.daytrader.web.TradeBuildDB.<init>(TradeBuildDB.java:196)
>>     at
>> org.apache.geronimo.samples.daytrader.web.TradeConfigServlet.service(TradeConfigServlet.java:411)
>>     at javax.servlet.http.HttpServlet.service(HttpServlet.java:806)
>>     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:191)
>>     at
>> org.apache.geronimo.tomcat.GeronimoStandardContext$SystemMethodValve.invoke(GeronimoStandardContext.java:420)
>>     at
>> org.apache.geronimo.tomcat.valve.GeronimoBeforeAfterValve.invoke(GeronimoBeforeAfterValve.java:47)
>>     at
>> org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
>>     at
>> org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
>>     at
>> org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:567)
>>     at
>> org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
>>     at
>> org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
>>     at
>> org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:849)
>>     at
>> org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
>>     at
>> org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:361)
>>     at org.apache.geronimo.pool.ThreadPool$1.run(ThreadPool.java:214)
>>     at
>> org.apache.geronimo.pool.ThreadPool$ContextClassLoaderRunnable.run(ThreadPool.java:344)
>>     at
>> java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
>>     at
>> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
>>     at java.lang.Thread.run(Thread.java:619)
>>
>> Then I had a peek at the code, and think this NPE might be caused by
>> PersistenceContext not injected in TradeJPADirect. Since TradeJPADirect
>> is not a web container managed object(not servlet or context listener),
>> so the annotation @PersistenceContext does not work.
>>
>> I guess daytrader-web-jpa assembly is to demo jpa usage in web module
>> without session EJB involvement. If we want to demo container-managed
>> entity manager via this assembly, we shall use @PersistenceContext on
>> servlet or any web container managed object, then use JNDI lookup to get
>> the entity manager from container. If we want to demo
>> application-managed entity manager, we can use @PersistenceUnit to
>> inject an EntityManagerFactory object in any web container managed
>> object, then use EntityManagerFactory.createEntityManager() to get
>> entity manager.
>>
>> Please kindly let me know your thoughts.
>>
>> Thanks!
>> Forrest
> 


Re: about daytrader-web-jpa

Posted by Donald Woods <dw...@apache.org>.
I'd prefer the application managed approach, as the Java EE version of
Daytrader uses container managed.

Thanks for helping with this.


-Donald


On 1/20/10 2:10 AM, Forrest Xia wrote:
> Hi Donald,
> 
> I tried the new assembly of daytrader -- daytrader-web-jpa, and did not
> get it work. The console log an error:
> 
> 2010-01-20 14:08:24,774 ERROR [Log] Error: TradeJPADirect:createQuote --
> exception creating Quote
>     java.lang.NullPointerException
> java.lang.NullPointerException
>     at
> org.apache.geronimo.samples.daytrader.core.direct.TradeJPADirect.createQuote(TradeJPADirect.java:418)
>     at
> org.apache.geronimo.samples.daytrader.core.TradeAction.createQuote(TradeAction.java:373)
>     at
> org.apache.geronimo.samples.daytrader.web.TradeBuildDB.<init>(TradeBuildDB.java:196)
>     at
> org.apache.geronimo.samples.daytrader.web.TradeConfigServlet.service(TradeConfigServlet.java:411)
>     at javax.servlet.http.HttpServlet.service(HttpServlet.java:806)
>     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:191)
>     at
> org.apache.geronimo.tomcat.GeronimoStandardContext$SystemMethodValve.invoke(GeronimoStandardContext.java:420)
>     at
> org.apache.geronimo.tomcat.valve.GeronimoBeforeAfterValve.invoke(GeronimoBeforeAfterValve.java:47)
>     at
> org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
>     at
> org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
>     at
> org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:567)
>     at
> org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
>     at
> org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
>     at
> org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:849)
>     at
> org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
>     at
> org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:361)
>     at org.apache.geronimo.pool.ThreadPool$1.run(ThreadPool.java:214)
>     at
> org.apache.geronimo.pool.ThreadPool$ContextClassLoaderRunnable.run(ThreadPool.java:344)
>     at
> java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
>     at
> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
>     at java.lang.Thread.run(Thread.java:619)
> 
> Then I had a peek at the code, and think this NPE might be caused by
> PersistenceContext not injected in TradeJPADirect. Since TradeJPADirect
> is not a web container managed object(not servlet or context listener),
> so the annotation @PersistenceContext does not work.
> 
> I guess daytrader-web-jpa assembly is to demo jpa usage in web module
> without session EJB involvement. If we want to demo container-managed
> entity manager via this assembly, we shall use @PersistenceContext on
> servlet or any web container managed object, then use JNDI lookup to get
> the entity manager from container. If we want to demo
> application-managed entity manager, we can use @PersistenceUnit to
> inject an EntityManagerFactory object in any web container managed
> object, then use EntityManagerFactory.createEntityManager() to get
> entity manager.
> 
> Please kindly let me know your thoughts.
> 
> Thanks!
> Forrest

Re: about daytrader-web-jpa

Posted by Joe Bohn <jo...@earthlink.net>.
Forrest Xia wrote:
> After some tries, finally I made daytrader-web-jpa works, see jira 
> https://issues.apache.org/jira/browse/DAYTRADER-74.
> 
> Joe, your version of TradeJPADirect has a small bug in completeOrder 
> method, see the patch code, I think it could be back port to the 
> blueprint one :-)

Thanks Forrest.  I think the line that you removed from createHolding 
was not in my sandbox version - so I think we're ok.  I assume that is 
the change you intended since I didn't see any change in completeOrder. 
  Please let me know if I'm missing something.

Thanks,
Joe

> 
> Donald, in the web jpa assembly pom, there are some dependencies are of 
> provided scope, I think if we need to make them packaged into the war 
> directly, so that user can easily install the war into Tomcat without 
> any advanced libraries installation. Does it make sense to make the 
> assembly ease of use?
> 
> However, in my tries, I ever want to use application managed persistence 
> context with JTA underlying on geronimo javaee assembly, but failed 
> always. So I want to ask a question: Can user use application-managed 
> persistence context with JTA underlying in a non-container managed 
> object? for example, in a POJO class? Seems to me, the answer is NO.
> 
> As to whether or not work if using app-managed PC with JTA underlying in 
> a container-managed object, for example, stateless session bean, 
> servlet, etc.
> 
> I will find time later to verify. However, if anyone has similar 
> experience, pls kindly let me know.
> 
> Forrest


Re: about daytrader-web-jpa

Posted by Donald Woods <dw...@apache.org>.
Yep, put a copy in both for now.  Thanks.


-Donald


On 1/22/10 11:53 AM, Forrest Xia wrote:
> Another issue is https://issues.apache.org/jira/browse/DAYTRADER-70. I
> ever provided a patch, but later the patch was reverted.
> 
> The problem is if there is no persistence.xml in ejb3 module, the javaee
> assembly in Full EJB3 mode won't work. Seems it's a bug of Geronimo.
> 
> So to overcome the bug, a workaround is to make a copy in both entities
> and ejb3 module. If that is acceptable, I can make a patch for that. pls
> let me know your thoughts. thanks!
> 
> I will do more testing, so that the daytrader trunk code could be in a
> good shape for a release.
> 
> Forrest

Re: about daytrader-web-jpa

Posted by Forrest Xia <fo...@gmail.com>.
Another issue is https://issues.apache.org/jira/browse/DAYTRADER-70. I ever
provided a patch, but later the patch was reverted.

The problem is if there is no persistence.xml in ejb3 module, the javaee
assembly in Full EJB3 mode won't work. Seems it's a bug of Geronimo.

So to overcome the bug, a workaround is to make a copy in both entities and
ejb3 module. If that is acceptable, I can make a patch for that. pls let me
know your thoughts. thanks!

I will do more testing, so that the daytrader trunk code could be in a good
shape for a release.

Forrest

Re: about daytrader-web-jpa

Posted by Donald Woods <dw...@apache.org>.
I would rather not include the missing depends, as we want to allow
users to use the web-jpa WAR with other providers besides the one we
ship in Geronimo (like running with Hibernate or Eclipselink for runtime
behavior comparisons.....)

We should include in the README that the user or app server container
has to provide the required jars, which each vendor (like OpenJPA or
Hibernate) should mention already.


-Donald


On 1/22/10 11:45 AM, Forrest Xia wrote:
> After some tries, finally I made daytrader-web-jpa works, see jira
> https://issues.apache.org/jira/browse/DAYTRADER-74.
> 
> Joe, your version of TradeJPADirect has a small bug in completeOrder
> method, see the patch code, I think it could be back port to the
> blueprint one :-)
> 
> Donald, in the web jpa assembly pom, there are some dependencies are of
> provided scope, I think if we need to make them packaged into the war
> directly, so that user can easily install the war into Tomcat without
> any advanced libraries installation. Does it make sense to make the
> assembly ease of use?
> 
> However, in my tries, I ever want to use application managed persistence
> context with JTA underlying on geronimo javaee assembly, but failed
> always. So I want to ask a question: Can user use application-managed
> persistence context with JTA underlying in a non-container managed
> object? for example, in a POJO class? Seems to me, the answer is NO.
> 
> As to whether or not work if using app-managed PC with JTA underlying in
> a container-managed object, for example, stateless session bean,
> servlet, etc.
> 
> I will find time later to verify. However, if anyone has similar
> experience, pls kindly let me know.
> 
> Forrest

Re: about daytrader-web-jpa

Posted by Forrest Xia <fo...@gmail.com>.
After some tries, finally I made daytrader-web-jpa works, see jira
https://issues.apache.org/jira/browse/DAYTRADER-74.

Joe, your version of TradeJPADirect has a small bug in completeOrder method,
see the patch code, I think it could be back port to the blueprint one :-)

Donald, in the web jpa assembly pom, there are some dependencies are of
provided scope, I think if we need to make them packaged into the war
directly, so that user can easily install the war into Tomcat without any
advanced libraries installation. Does it make sense to make the assembly
ease of use?

However, in my tries, I ever want to use application managed persistence
context with JTA underlying on geronimo javaee assembly, but failed always.
So I want to ask a question: Can user use application-managed persistence
context with JTA underlying in a non-container managed object? for example,
in a POJO class? Seems to me, the answer is NO.

As to whether or not work if using app-managed PC with JTA underlying in a
container-managed object, for example, stateless session bean, servlet, etc.

I will find time later to verify. However, if anyone has similar experience,
pls kindly let me know.

Forrest

Re: about daytrader-web-jpa

Posted by Donald Woods <dw...@apache.org>.
OK, made the PersistenceContext -> PersistenceUnit change but still no
luck running it on a stand-alone Tomcat 6.0.20....

I'm still seeing OpenJPA problems in getting the db connection.

org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create
PoolableConnectionFactory (Failed to start database 'tradedb', see the
next exception for details.)



-Donald


On 1/20/10 2:10 AM, Forrest Xia wrote:
> Hi Donald,
> 
> I tried the new assembly of daytrader -- daytrader-web-jpa, and did not
> get it work. The console log an error:
> 
> 2010-01-20 14:08:24,774 ERROR [Log] Error: TradeJPADirect:createQuote --
> exception creating Quote
>     java.lang.NullPointerException
> java.lang.NullPointerException
>     at
> org.apache.geronimo.samples.daytrader.core.direct.TradeJPADirect.createQuote(TradeJPADirect.java:418)
>     at
> org.apache.geronimo.samples.daytrader.core.TradeAction.createQuote(TradeAction.java:373)
>     at
> org.apache.geronimo.samples.daytrader.web.TradeBuildDB.<init>(TradeBuildDB.java:196)
>     at
> org.apache.geronimo.samples.daytrader.web.TradeConfigServlet.service(TradeConfigServlet.java:411)
>     at javax.servlet.http.HttpServlet.service(HttpServlet.java:806)
>     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:191)
>     at
> org.apache.geronimo.tomcat.GeronimoStandardContext$SystemMethodValve.invoke(GeronimoStandardContext.java:420)
>     at
> org.apache.geronimo.tomcat.valve.GeronimoBeforeAfterValve.invoke(GeronimoBeforeAfterValve.java:47)
>     at
> org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
>     at
> org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
>     at
> org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:567)
>     at
> org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
>     at
> org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
>     at
> org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:849)
>     at
> org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
>     at
> org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:361)
>     at org.apache.geronimo.pool.ThreadPool$1.run(ThreadPool.java:214)
>     at
> org.apache.geronimo.pool.ThreadPool$ContextClassLoaderRunnable.run(ThreadPool.java:344)
>     at
> java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
>     at
> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
>     at java.lang.Thread.run(Thread.java:619)
> 
> Then I had a peek at the code, and think this NPE might be caused by
> PersistenceContext not injected in TradeJPADirect. Since TradeJPADirect
> is not a web container managed object(not servlet or context listener),
> so the annotation @PersistenceContext does not work.
> 
> I guess daytrader-web-jpa assembly is to demo jpa usage in web module
> without session EJB involvement. If we want to demo container-managed
> entity manager via this assembly, we shall use @PersistenceContext on
> servlet or any web container managed object, then use JNDI lookup to get
> the entity manager from container. If we want to demo
> application-managed entity manager, we can use @PersistenceUnit to
> inject an EntityManagerFactory object in any web container managed
> object, then use EntityManagerFactory.createEntityManager() to get
> entity manager.
> 
> Please kindly let me know your thoughts.
> 
> Thanks!
> Forrest