Somehow the PersistenceContext is not getting injected.
-Can you spot any exception in server.log at deployment ?
-Can you please post how you are packaging your application?
glassfish_at_javadesktop.org wrote:
> Hello
>
> [b]Hibernate version:[/b] 3.2.5
> [b]Glassfish:[/b]2ur2
>
> I have read some articles where people did manage to get this to work but I keep getting an exception even with the simplest example. The exception happens on em.persist().
> All is packaged inside the .war file. I also tried putting the bean and model class in an ejb jar but it didn't help.
>
> I did copy the hibernate libraries into glassfish/lib as some posts online suggested.
>
> [b]The bean:[/b]
> [code]
> package com.test.service.jpa;
> import ...
> @Remote
> public interface BookRemote {
> void create(Book book);
> void remove(Book book);
> Book find(Object id);
> }
>
> package com.test.service.jpa;
> import ...
> @Stateless
> public class BookBean implements BookRemote {
>
> @PersistenceContext(unitName = "MyPU")
> private EntityManager em;
>
> public void create(Book book) {em.persist(book);}
> public void remove(Book book) {em.remove(book);}
> public Book find(Object id) {return em.find(be.kzen.service.jpa.Book.class, id);}
> }
> [/code]
>
> [b]The usage:[/b]
> [code]
> package com.test.service;
> import ...
> @WebService()
> public class BookWebService {
> public boolean add(String title) {
> BookBean s = new BookBean();
> Book book = new Book(title);
> s.create(book);
> return true;
> }
> }
> [/code]
>
> [b]The config:[/b]
> [code]
> <?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="MyPU" transaction-type="JTA">
> <provider>org.hibernate.ejb.HibernatePersistence</provider>
> <jta-data-source>jdbc/mysample</jta-data-source>
> <properties>
> <property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect"/>
> <property name="hibernate.hbm2ddl.auto" value="update"/>
> </properties>
> </persistence-unit>
> </persistence>
> [/code]
>
> [b]The exception:[/b]
> [code]
> The log message is null.
> java.lang.NullPointerException
> at com.test.service.jpa.BookBean.create(BookBean.java:18)
> at com.test.service.NewWebService.add(NewWebService.java:21)
> 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 com.sun.enterprise.webservice.InstanceResolverImpl$1.invoke(InstanceResolverImpl.java:112)
> at com.sun.xml.ws.server.InvokerTube$2.invoke(InvokerTube.java:146)
> at com.sun.xml.ws.server.sei.EndpointMethodHandler.invoke(EndpointMethodHandler.java:257)
> at com.sun.xml.ws.server.sei.SEIInvokerTube.processRequest(SEIInvokerTube.java:93)
> at com.sun.xml.ws.api.pipe.Fiber.__doRun(Fiber.java:595)
> at com.sun.xml.ws.api.pipe.Fiber._doRun(Fiber.java:554)
> at com.sun.xml.ws.api.pipe.Fiber.doRun(Fiber.java:539)
> at com.sun.xml.ws.api.pipe.Fiber.runSync(Fiber.java:436)
> at com.sun.xml.ws.api.pipe.helper.AbstractTubeImpl.process(AbstractTubeImpl.java:106)
> at com.sun.enterprise.webservice.MonitoringPipe.process(MonitoringPipe.java:147)
> at com.sun.xml.ws.api.pipe.helper.PipeAdapter.processRequest(PipeAdapter.java:115)
> at com.sun.xml.ws.api.pipe.Fiber.__doRun(Fiber.java:595)
> at com.sun.xml.ws.api.pipe.Fiber._doRun(Fiber.java:554)
> at com.sun.xml.ws.api.pipe.Fiber.doRun(Fiber.java:539)
> at com.sun.xml.ws.api.pipe.Fiber.runSync(Fiber.java:436)
> at com.sun.xml.ws.api.pipe.helper.AbstractTubeImpl.process(AbstractTubeImpl.java:106)
> at com.sun.enterprise.webservice.CommonServerSecurityPipe.processRequest(CommonServerSecurityPipe.java:218)
> at com.sun.enterprise.webservice.CommonServerSecurityPipe.process(CommonServerSecurityPipe.java:129)
> at com.sun.xml.ws.api.pipe.helper.PipeAdapter.processRequest(PipeAdapter.java:115)
> at com.sun.xml.ws.api.pipe.Fiber.__doRun(Fiber.java:595)
> at com.sun.xml.ws.api.pipe.Fiber._doRun(Fiber.java:554)
> at com.sun.xml.ws.api.pipe.Fiber.doRun(Fiber.java:539)
> at com.sun.xml.ws.api.pipe.Fiber.runSync(Fiber.java:436)
> at com.sun.xml.ws.server.WSEndpointImpl$2.process(WSEndpointImpl.java:243)
> at com.sun.xml.ws.transport.http.HttpAdapter$HttpToolkit.handle(HttpAdapter.java:444)
> at com.sun.xml.ws.transport.http.HttpAdapter.handle(HttpAdapter.java:244)
> at com.sun.xml.ws.transport.http.servlet.ServletAdapter.handle(ServletAdapter.java:135)
> at com.sun.enterprise.webservice.JAXWSServlet.doPost(JAXWSServlet.java:176)
> at javax.servlet.http.HttpServlet.service(HttpServlet.java:738)
> at javax.servlet.http.HttpServlet.service(HttpServlet.java:831)
> at org.apache.catalina.core.ApplicationFilterChain.servletService(ApplicationFilterChain.java:411)
> at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:317)
> at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:198)
> at org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:390)
> at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:230)
> at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:198)
> at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:288)
> at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:271)
> at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:202)
> at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:632)
> at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:577)
> at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:94)
> at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:206)
> at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:632)
> at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:577)
> at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:571)
> at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1080)
> at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:150)
> at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:632)
> at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:577)
> at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:571)
> at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1080)
> at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:272)
> at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.invokeAdapter(DefaultProcessorTask.java:637)
> at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.doProcess(DefaultProcessorTask.java:568)
> at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.process(DefaultProcessorTask.java:813)
> at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.executeProcessorTask(DefaultReadTask.java:341)
> at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.doTask(DefaultReadTask.java:263)
> at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.doTask(DefaultReadTask.java:214)
> at com.sun.enterprise.web.portunif.PortUnificationPipeline$PUTask.doTask(PortUnificationPipeline.java:380)
> at com.sun.enterprise.web.connector.grizzly.TaskBase.run(TaskBase.java:265)
> at com.sun.enterprise.web.connector.grizzly.ssl.SSLWorkerThread.run(SSLWorkerThread.java:106)
> [/code]
>
> Thanks in advance for any hints
> [Message sent by forum member 'marlor' (marlor)]
>
> http://forums.java.net/jive/thread.jspa?messageID=293012
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: users-help_at_glassfish.dev.java.net
>
>