7 Replies Latest reply on Oct 25, 2012 8:18 PM by gimbal2

    @EJB and @PersistenceContext not working in JBOSS.5.1.0.GA?

      I am implementing a Rest Webservice Using RESTEasy and JPA for persistance and deploying in JBOSS.5.1.0.GA. JPA is working fine when we are getting EMF and EM programmatically.

      emf = Persistence.createEntityManagerFactory(Constants.GTL_ORACLE_PERSISTENCE_UNIT);
      em = emf.createEntityManager();

      But when I tried to inject EntityManager using @PersistenceContext . I am getting null value.

      Now we tried it using @Stateless EJB but that too failed in our service class.

      Our Service class is as follows:-

      public class ProductResourceService implements ProductResource {

      private boolean oneTime = false;
      @EJB(mappedName = "MyService")
      private PersistanceService persistanceService;

      public String saveProduct(@PathParam("id") String id) {
      System.out.println("requset got id[" + id + "]");

      Product product = new Product();
      product.setDescription("testing Persistance");
      String status = "Failed";
      try {
      System.out.println("persistanceService " + persistanceService);

      status = "Success";
      } catch (Exception e) {
      System.out.println("Error" + e);
      return status;



      @Stateless(mappedName = "MyService")
      public class PersistanceService implements PersistanceServiceLocal {

      private EntityManager em;

      public void setEm(EntityManager em) {
      this.em = em;

      public void saveObject(Object obj) {

      try {
      } finally {


      public Object getSingleResultSet(String namedQuery) {

      Query query = null;
      try {
      query = em.createNamedQuery(namedQuery);
      } finally {
      if (query == null) {
      return null;
      return query.getSingleResult();


      I have persistence.xml configured in this way.

      <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="productDetails" transaction-type="JTA" >

      <property name="hibernate.dialect" value="org.hibernate.dialect.OracleDialect" />
      <property name="hibernate.hbm2ddl.auto"
      value="create-drop" />



      Can you please tell me where I went wrong.I have been spending several days trying to resolve it....Is it that @PersistenceContext is not supported by JBOSS 5.1.0GA???

      Any help will be appreciated.

      Edited by: Ryan Jimmy on Oct 24, 2012 10:57 PM