Problem running the bookstore6 example from J2EE 1.5 Tutorial

Hi,

I got the bookstore6 example running on my windows XP box within glassfish. I am able access the URL http://localhost:8080/bookstore6. But whenever I click on the map or a link to pick a locale, I get an exception. Below is what I see in the server log file. Any help is appreciated.

[#|2006-08-15T15:15:59.147-0700|WARNING|sun-appserver-pe9.1|javax.enterprise.resource.webcontainer.jsf.lifecycle|_ThreadID=13;_ThreadName=httpWorkerThread-8080-0;_RequestID=fcb38d2f-9e92-4a7b-a439-0715d61ed98a;|executePhase(INVOKE_APPLICATION 5,com.sun.faces.context.FacesContextImpl@135b92e) threw exception

javax.faces.FacesException: javax.faces.FacesException: com.sun.enterprise.InjectionException: Exception attempting to inject Env-Prop: books@Field-Injectable Resource. Class name = com.sun.bookstore6.backing.AbstractBean Field name=em@java.lang.String@@@ into class com.sun.bookstore6.backing.AbstractBean

at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:105)

at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:244)

at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:113)

at javax.faces.webapp.FacesServlet.service(FacesServlet.java:244)

at org.apache.catalina.core.ApplicationFilterChain.servletService(ApplicationFilterChain.java:397)

at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:278)

at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:586)

at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:556)

at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:246)

at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:185)

at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:586)

at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:73)

at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:182)

at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:586)

at com.sun.enterprise.web.VirtualServerPipeline.invoke(VirtualServerPipeline.java:120)

at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:939)

at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:137)

at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:586)

at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:556)

at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:939)

at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:231)

at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.invokeAdapter(DefaultProcessorTask.java:619)

at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.processNonBlocked(DefaultProcessorTask.java:550)

at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.process(DefaultProcessorTask.java:780)

at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.executeProcessorTask(DefaultReadTask.java:326)

at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.doTask(DefaultReadTask.java:251)

at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.doTask(DefaultReadTask.java:205)

at com.sun.enterprise.web.connector.grizzly.TaskBase.run(TaskBase.java:252)

at com.sun.enterprise.web.connector.grizzly.WorkerThreadImpl.run(WorkerThreadImpl.java:103)

Caused by: javax.faces.FacesException: javax.faces.FacesException: com.sun.enterprise.InjectionException: Exception attempting to inject Env-Prop: books@Field-Injectable Resource. Class name = com.sun.bookstore6.backing.AbstractBean Field name=em@java.lang.String@@@ into class com.sun.bookstore6.backing.AbstractBean

at com.sun.faces.application.ApplicationAssociate.createAndMaybeStoreManagedBeans(ApplicationAssociate.java:521)

at com.sun.faces.el.ManagedBeanELResolver.getValue(ManagedBeanELResolver.java:82)

at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:143)

at com.sun.faces.el.FacesCompositeELResolver.getValue(FacesCompositeELResolver.java:62)

at com.sun.el.parser.AstIdentifier.getValue(AstIdentifier.java:68)

at com.sun.el.parser.AstValue.getTarget(AstValue.java:63)

at com.sun.el.parser.AstValue.invoke(AstValue.java:153)

at com.sun.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:283)

at javax.faces.event.MethodExpressionActionListener.processAction(MethodExpressionActionListener.java:88)

at javax.faces.event.ActionEvent.processListener(ActionEvent.java:77)

at javax.faces.component.UIComponentBase.broadcast(UIComponentBase.java:776)

at javax.faces.component.UICommand.broadcast(UICommand.java:368)

at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:471)

at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:783)

at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:97)

... 28 more

Caused by: javax.faces.FacesException: com.sun.enterprise.InjectionException: Exception attempting to inject Env-Prop: books@Field-Injectable Resource. Class name = com.sun.bookstore6.backing.AbstractBean Field name=em@java.lang.String@@@ into class com.sun.bookstore6.backing.AbstractBean

at com.sun.faces.config.ManagedBeanFactoryImpl.newInstance(ManagedBeanFactoryImpl.java:325)

at com.sun.faces.application.ApplicationAssociate.createAndMaybeStoreManagedBeans(ApplicationAssociate.java:510)

... 42 more

Caused by: com.sun.enterprise.InjectionException: Exception attempting to inject Env-Prop: books@Field-Injectable Resource. Class name = com.sun.bookstore6.backing.AbstractBean Field name=em@java.lang.String@@@ into class com.sun.bookstore6.backing.AbstractBean

at com.sun.enterprise.util.InjectionManagerImpl._inject(InjectionManagerImpl.java:373)

at com.sun.enterprise.util.InjectionManagerImpl.inject(InjectionManagerImpl.java:193)

at com.sun.enterprise.util.InjectionManagerImpl.injectInstance(InjectionManagerImpl.java:87)

at com.sun.faces.vendor.GlassFishInjectionProvider.inject(GlassFishInjectionProvider.java:65)

at com.sun.faces.config.ManagedBeanFactoryImpl.newInstance(ManagedBeanFactoryImpl.java:312)

... 43 more

Caused by: com.sun.enterprise.InjectionException: Illegal use of static field private static javax.persistence.EntityManager com.sun.bookstore6.backing.AbstractBean.em on class that only supports instance-based injection

at com.sun.enterprise.util.InjectionManagerImpl._inject(InjectionManagerImpl.java:292)

... 47 more

|#]

[#|2006-08-15T15:15:59.163-0700|SEVERE|sun-appserver-pe9.1|javax.enterprise.system.container.web|_ThreadID=13;_ThreadName=httpWorkerThread-8080-0;_RequestID=fcb38d2f-9e92-4a7b-a439-0715d61ed98a;|StandardWrapperValve[FacesServlet]: PWC1406: Servlet.service() for servlet FacesServlet threw exception

com.sun.enterprise.InjectionException: Illegal use of static field private static javax.persistence.EntityManager com.sun.bookstore6.backing.AbstractBean.em on class that only supports instance-based injection

at com.sun.enterprise.util.InjectionManagerImpl._inject(InjectionManagerImpl.java:292)

at com.sun.enterprise.util.InjectionManagerImpl.inject(InjectionManagerImpl.java:193)

at com.sun.enterprise.util.InjectionManagerImpl.injectInstance(InjectionManagerImpl.java:87)

at com.sun.faces.vendor.GlassFishInjectionProvider.inject(GlassFishInjectionProvider.java:65)

at com.sun.faces.config.ManagedBeanFactoryImpl.newInstance(ManagedBeanFactoryImpl.java:312)

at com.sun.faces.application.ApplicationAssociate.createAndMaybeStoreManagedBeans(ApplicationAssociate.java:510)

at com.sun.faces.el.ManagedBeanELResolver.getValue(ManagedBeanELResolver.java:82)

at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:143)

at com.sun.faces.el.FacesCompositeELResolver.getValue(FacesCompositeELResolver.java:62)

at com.sun.el.parser.AstIdentifier.getValue(AstIdentifier.java:68)

at com.sun.el.parser.AstValue.getTarget(AstValue.java:63)

at com.sun.el.parser.AstValue.invoke(AstValue.java:153)

at com.sun.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:283)

at javax.faces.event.MethodExpressionActionListener.processAction(MethodExpressionActionListener.java:88)

at javax.faces.event.ActionEvent.processListener(ActionEvent.java:77)

at javax.faces.component.UIComponentBase.broadcast(UIComponentBase.java:776)

at javax.faces.component.UICommand.broadcast(UICommand.java:368)

at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:471)

at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:783)

at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:97)

at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:244)

at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:113)

at javax.faces.webapp.FacesServlet.service(FacesServlet.java:244)

at org.apache.catalina.core.ApplicationFilterChain.servletService(ApplicationFilterChain.java:397)

at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:278)

at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:586)

at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:556)

at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:246)

at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:185)

at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:586)

at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:73)

at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:182)

at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:586)

at com.sun.enterprise.web.VirtualServerPipeline.invoke(VirtualServerPipeline.java:120)

at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:939)

at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:137)

at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:586)

at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:556)

at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:939)

at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:231)

at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.invokeAdapter(DefaultProcessorTask.java:619)

at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.processNonBlocked(DefaultProcessorTask.java:550)

at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.process(DefaultProcessorTask.java:780)

at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.executeProcessorTask(DefaultReadTask.java:326)

at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.doTask(DefaultReadTask.java:251)

at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.doTask(DefaultReadTask.java:205)

at com.sun.enterprise.web.connector.grizzly.TaskBase.run(TaskBase.java:252)

at com.sun.enterprise.web.connector.grizzly.WorkerThreadImpl.run(WorkerThreadImpl.java:103)

|#]

Message was edited by:

hongyan99

Message was edited by:

hongyan99

[11743 byte] By [hongyan99a] at [2007-10-3 2:48:26]
# 1
Did you ever resolve this problem? I'm now running into it.
DummyNo1a at 2007-7-14 20:37:14 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 2
Nevermind, I sorted it out.
DummyNo1a at 2007-7-14 20:37:14 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 3
I am having this problem and I would rather not spend anymore time figuring out how to get this tutorial working. So if anyone knows the solution, I would appreciate a post here.
wgoldmana at 2007-7-14 20:37:14 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 4
What was the problem? How did you solve it? Thanks!
hongyan99a at 2007-7-14 20:37:14 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 5

I'm not 100% sure that this is the correct solution, but it works for me. I modified the em field in the com.sun.bookstore6.backing.AbstractBean class to no longer be static. My code now looks like:

@PersistenceContext(name = "books")

private EntityManager em;

The reason that I did this was that I found the code that generated the exception and saw that it was doing a modifier check on the field before doing the injection. If an object instance was supplied to the injection code, the field being injected could not be static.

I also found this page http://blogs.sun.com/chengfang/entry/do_s_and_don_ts which contains a list of things to do and not to do with respect to resource injection. Points 5 and 6 in this list I think are relevant. If I have read and understood this correctly, then the provided code has a bug in it as the AbstractBean class is not an application client main class. At the time of posting, I was not able to download the JavaEE Specification to read on this further.

Hopefully, if I've got this wrong, someone will correct me. Especially if they have already solved the problem.

Matt_Dragoa at 2007-7-14 20:37:14 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 6
Thanks a lot Matt. I posted the question a couple of month and now I get the answer on my birthday! Thanks so much!
hongyan99a at 2007-7-14 20:37:14 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 7

I got this same problem. But when I droped static from the original code I get another error. Please help.

[#|2006-12-13T14:37:41.806+0100|SEVERE|sun-appserver-pe9.0|javax.enterprise.system.container.web|_ThreadID=13;_ThreadName=httpWorkerThread-8080-1;_RequestID=66d98196-7004-4c04-8255-0391a8077d16;|StandardWrapperValve[FacesServlet]: Servlet.service() for servlet FacesServlet threw exception

javax.faces.FacesException: Could not get book details com.sun.bookstore.exception.BooksNotFoundException: Could not get books: Unable to retrieve EntityManagerFactory for unitName null

at com.sun.bookstore6.backing.BookstoreBean.getFeatured(BookstoreBean.java:58)

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:585)

at javax.el.BeanELResolver.getValue(BeanELResolver.java:273)

at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:143)

at com.sun.faces.el.FacesCompositeELResolver.getValue(FacesCompositeELResolver.java:62)

at com.sun.el.parser.AstValue.getValue(AstValue.java:117)

at com.sun.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:192)

at javax.faces.component.UIOutput.getValue(UIOutput.java:173)

at com.sun.faces.renderkit.html_basic.HtmlBasicInputRenderer.getValue(HtmlBasicInputRenderer.java:100)

at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.getCurrentValue(HtmlBasicRenderer.java:279)

at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeEnd(HtmlBasicRenderer.java:207)

at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:848)

at com.sun.faces.renderkit.html_basic.CommandLinkRenderer.encodeChildren(CommandLinkRenderer.java:203)

at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:828)

at javax.faces.component.UIComponent.encodeAll(UIComponent.java:883)

at javax.faces.render.Renderer.encodeChildren(Renderer.java:137)

at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:828)

at javax.faces.component.UIComponent.encodeAll(UIComponent.java:883)

at javax.faces.component.UIComponent.encodeAll(UIComponent.java:889)

at com.sun.faces.application.ViewHandlerImpl.doRenderView(ViewHandlerImpl.java:271)

at com.sun.faces.application.ViewHandlerImpl.renderView(ViewHandlerImpl.java:182)

at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:133)

at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:244)

at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:140)

at javax.faces.webapp.FacesServlet.service(FacesServlet.java:245)

at org.apache.catalina.core.ApplicationFilterChain.servletService(ApplicationFilterChain.java:397)

at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:278)

at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:566)

at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:536)

at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:240)

at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:179)

at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:566)

at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:73)

at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:182)

at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:566)

at com.sun.enterprise.web.VirtualServerPipeline.invoke(VirtualServerPipeline.java:120)

at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:939)

at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:137)

at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:566)

at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:536)

at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:939)

at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:239)

at com.sun.enterprise.web.connector.grizzly.ProcessorTask.invokeAdapter(ProcessorTask.java:667)

at com.sun.enterprise.web.connector.grizzly.ProcessorTask.processNonBlocked(ProcessorTask.java:574)

at com.sun.enterprise.web.connector.grizzly.ProcessorTask.process(ProcessorTask.java:844)

at com.sun.enterprise.web.connector.grizzly.ReadTask.executeProcessorTask(ReadTask.java:287)

at com.sun.enterprise.web.connector.grizzly.ReadTask.doTask(ReadTask.java:212)

at com.sun.enterprise.web.connector.grizzly.TaskBase.run(TaskBase.java:252)

at com.sun.enterprise.web.connector.grizzly.WorkerThread.run(WorkerThread.java:75)

|#]

Message was edited by:

dujemalenica

dujemalenicaa at 2007-7-14 20:37:14 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...