ronny ron
2013-04-20 20:11:09 UTC
ronny ron [https://community.jboss.org/people/ronny.ron] created the discussion
"restful webservice with ejb anotation @PersistenceContext"
To view the discussion, visit: https://community.jboss.org/message/809402#809402
--------------------------------------------------------------
hello im trying to create a resful 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 http://java.sun.com/xml/ns/persistence" xmlns:xsi=" http://www.w3.org/2001/XMLSchema-instance http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation=" http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd 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: Loading Image... Loading Image...
can anyone help me with this please?
thanks in advance, Ronny.
--------------------------------------------------------------
Reply to this message by going to Community
[https://community.jboss.org/message/809402#809402]
Start a new discussion in JNDI and Naming at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2083]
"restful webservice with ejb anotation @PersistenceContext"
To view the discussion, visit: https://community.jboss.org/message/809402#809402
--------------------------------------------------------------
hello im trying to create a resful 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 http://java.sun.com/xml/ns/persistence" xmlns:xsi=" http://www.w3.org/2001/XMLSchema-instance http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation=" http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd 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: Loading Image... Loading Image...
can anyone help me with this please?
thanks in advance, Ronny.
--------------------------------------------------------------
Reply to this message by going to Community
[https://community.jboss.org/message/809402#809402]
Start a new discussion in JNDI and Naming at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2083]