1 Reply Latest reply on Sep 3, 2010 3:57 AM by jaikiran

    Global JNDI names dissapear after using annotation @PersistenceContext

    ggolebio

      Hi,

       

      I discovered that when I'm use @PersistenceContext annotation then after deploy i lost some global JNDI names.

       

      (Example project is ready in attachment)

       

      For example in my EJB I have 3 classes : Number, NumberArabic and NumberRome.

      Number is Remote and NumberArabic and NumberRome are local.

      When I deploy my ear without @PersistenceContext annotation then below JNDI names are produced :

       

       

      InjectionTestEar/NumberArabic/local - EJB3.x Default Local Business Interface
      InjectionTestEar/NumberArabic/local-ejb.injection.test.interfaces.NumberArabicInterface - EJB3.x Local Business Interface
      09:24:14,484 INFO  [org.jboss.ejb3.session.SessionSpecContainer] Starting jboss.j2ee:ear=InjectionTestEar.ear,jar=InjectionTestEJB.jar,name=NumberRome,service=EJB3
      09:24:14,486 INFO  [org.jboss.ejb3.EJBContainer] STARTED EJB: injectton.test.sessionbean.NumberRome ejbName: NumberRome
      09:24:14,523 INFO  [org.jboss.ejb3.proxy.impl.jndiregistrar.JndiSessionRegistrarBase] Binding the following Entries in Global JNDI:
      InjectionTestEar/NumberRome/local - EJB3.x Default Local Business Interface
      InjectionTestEar/NumberRome/local-ejb.injection.test.interfaces.NumberRomeInterface - EJB3.x Local Business Interface
      09:24:14,590 INFO  [org.jboss.ejb3.session.SessionSpecContainer] Starting jboss.j2ee:ear=InjectionTestEar.ear,jar=InjectionTestEJB.jar,name=Number,service=EJB3
      09:24:14,592 INFO  [org.jboss.ejb3.EJBContainer] STARTED EJB: injectton.test.sessionbean.Number ejbName: Number
      09:24:14,655 INFO  [org.jboss.ejb3.proxy.impl.jndiregistrar.JndiSessionRegistrarBase] Binding the following Entries in Global JNDI:
      Number - EJB3.x Default Remote Business Interface
      InjectionTestEar/Number/remote-ejb.injection.test.interfaces.NumberInterfaceRemote - EJB3.x Remote Business Interface
      InjectionTestEar/Number/local - EJB3.x Default Local Business Interface
      InjectionTestEar/Number/local-ejb.injection.test.interfaces.NumberInterfaceLocal - EJB3.x Local Business Interface

      InjectionTestEar/NumberArabic/local - EJB3.x Default Local Business Interface

      InjectionTestEar/NumberArabic/local-ejb.injection.test.interfaces.NumberArabicInterface - EJB3.x Local Business Interface

      ....

      InjectionTestEar/NumberRome/local - EJB3.x Default Local Business Interface

      InjectionTestEar/NumberRome/local-ejb.injection.test.interfaces.NumberRomeInterface - EJB3.x Local Business Interface

      ....

      Number - EJB3.x Default Remote Business Interface

      InjectionTestEar/Number/remote-ejb.injection.test.interfaces.NumberInterfaceRemote - EJB3.x Remote Business Interface

      InjectionTestEar/Number/local - EJB3.x Default Local Business Interface

      InjectionTestEar/Number/local-ejb.injection.test.interfaces.NumberInterfaceLocal - EJB3.x Local Business Interface

       

       

      When in NumberArabic class i use @PersistenceContext then i lost e.g. Number jndi name and then lookup from client is impossible.

      This is the NumberArabic class :

       

       

      package injectton.test.sessionbean;


      import injection.test.enums.NumType;


      import javax.ejb.Local;

      import javax.ejb.Stateful;

      import javax.persistence.PersistenceContext;

      import javax.persistence.PersistenceContexts;


      import ejb.injection.test.interfaces.NumberArabicInterface;


      //below annotation make problems

      //@PersistenceContexts({

      // @PersistenceContext(name="BlobDB1TypeUnit", unitName="BlobDB1TypeUnit"),

      // @PersistenceContext(name="BlobDB2TypeUnit", unitName="BlobDB2TypeUnit")

      //})


      @Local

      @Stateful

      public class NumberArabic implements NumberArabicInterface{

       

      public String getNumberType(NumType type) {

      return type.toString();

      }


      }

       

      In Result after deploy with uncommented @PersistenceContext annotation only below JNDI names are produced :

       

      InjectionTestEar/NumberRome/local - EJB3.x Default Local Business Interface

      InjectionTestEar/NumberRome/local-ejb.injection.test.interfaces.NumberRomeInterface - EJB3.x Local Business Interface

       

      I'm use JBoss 6 m4. Maybe someone know where the problem is? (Whole source code as eclipse projects are in attachment : InjectionTest.zip)


      Regards,
      Greg

        • 1. Re: Global JNDI names dissapear after using annotation @PersistenceContext
          jaikiran

          I gave it a quick try and just changed the persistence.xml file to point to java:DefaultDS as the jta-data-source:

           

          <?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="BlobDB1TypeUnit" transaction-type="JTA">
                  <provider>org.hibernate.ejb.HibernatePersistence</provider>
                  <jta-data-source>java:DefaultDS</jta-data-source>    
              </persistence-unit>
              <persistence-unit name="BlobDB2TypeUnit" transaction-type="JTA">
                  <provider>org.hibernate.ejb.HibernatePersistence</provider>
                  <jta-data-source>java:DefaultDS</jta-data-source>    
              </persistence-unit>
          </persistence>

           

           

          And did not change anything in the bean, it still looks:

           

          @PersistenceContexts({
              @PersistenceContext(name="BlobDB1TypeUnit", unitName="BlobDB1TypeUnit"),
              @PersistenceContext(name="BlobDB2TypeUnit", unitName="BlobDB2TypeUnit")
          })
          
          @Local
          @Stateful
          public class NumberArabic implements NumberArabicInterface{
              
              public String getNumberType(NumType type) {
                  return type.toString();
              }
          
          }
          

           

           

          And it deployed fine with the JNDI names:

           

          13:22:53,120 INFO  [EJBContainer] STARTED EJB: injectton.test.sessionbean.NumberArabic ejbName: NumberArabic
          13:22:53,122 INFO  [JndiSessionRegistrarBase] Binding the following Entries in Global JNDI:
          
              myapp/NumberArabic/local - EJB3.x Default Local Business Interface
              myapp/NumberArabic/local-ejb.injection.test.interfaces.NumberArabicInterface - EJB3.x Local Business Interface
          
          13:22:53,132 INFO  [SessionSpecContainer] Starting jboss.j2ee:ear=myapp.ear,jar=myapp-ejb.jar,name=Number,service=EJB3
          13:22:53,133 INFO  [EJBContainer] STARTED EJB: injectton.test.sessionbean.Number ejbName: Number
          13:22:53,153 INFO  [JndiSessionRegistrarBase] Binding the following Entries in Global JNDI:
          
              Number - EJB3.x Default Remote Business Interface
              myapp/Number/remote-ejb.injection.test.interfaces.NumberInterfaceRemote - EJB3.x Remote Business Interface
              myapp/Number/local - EJB3.x Default Local Business Interface
              myapp/Number/local-ejb.injection.test.interfaces.NumberInterfaceLocal - EJB3.x Local Business Interface
          

           

           

          So I'm guessing it's something to do with your persistence.xml and/or your -ds.xml file. What does the -ds.xml file look like and where have you palced that file?