1 Reply Latest reply on Apr 21, 2013 10:40 AM by wdfink

    restful webservice with ejb3 @PersistenceContext annotation

    ronny.ron

      hello im trying to create a restful application with ejb annotations

      but the persistenceContext is always null when entering the websevice

       

      the web.xml looks like this:

      <?xml version="1.0" encoding="UTF-8"?>
      <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
        <display-name>WebServiceTest</display-name>
      
      
                          <context-param>
              <param-name>resteasy.scan</param-name>
              <param-value>false</param-value>
      </context-param>
      <context-param>
              <param-name>resteasy.scan.resources</param-name>
              <param-value>false</param-value>
      </context-param>
      <context-param>
              <param-name>resteasy.scan.providers</param-name>
              <param-value>false</param-value>
      </context-param>
       <servlet>
          <servlet-name>Jersey REST Service</servlet-name>
          <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
          <init-param>
            <param-name>com.sun.jersey.config.property.packages</param-name>
            <param-value>test</param-value>
          </init-param>
          <load-on-startup>1</load-on-startup>
        </servlet>
        <servlet-mapping>
          <servlet-name>Jersey REST Service</servlet-name>
          <url-pattern>/rest/*</url-pattern>
        </servlet-mapping>
        <persistence-context-ref>
              <persistence-context-ref-name>test.Services/manager</persistence-context-ref-name>
              <persistence-unit-name>MyPersistenceUnit</persistence-unit-name>
          </persistence-context-ref>
      
      </web-app>
      

       

      the persistence.xml:

       

      <?xml version="1.0" encoding="UTF-8"?>
      <persistence version="2.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_2_0.xsd">
        <persistence-unit name="MyPersistenceUnit">
                    <jta-data-source>java:/jboss/myds</jta-data-source>
             <properties> 
                         <property name="hibernate.hbm2ddl.auto"/>  
                                    <!--value set to update will keep the DB between deployments-->
                                    <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/mtm_schema"/>
                                    <property name="javax.persistence.jdbc.user" value="root"/>
                                    <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
                                    <property name="javax.persistence.jdbc.password" value="admin"/>
      
                           </properties>
                </persistence-unit>
      </persistence>
      

       

      the class which provides the webservices:  Services.java begin like this:

       

       

       

       

      @Produces(MediaType.APPLICATION_JSON) 
      @Path("/service")
      @Stateless
      public class Services implements ServicesInterface{
      
                @PersistenceContext(name = "MyPersistenceUnit",   
                                    type=PersistenceContextType.TRANSACTION)
          private EntityManager manager;
      

       

      and while entering anytype of webservice function, the entitymanager called manager is null.

       

      project structure is as follows: eclispe.jpg

       

      can anyone help me with this please?

       

      thanks in advance, Ronny.