5 Replies Latest reply on Feb 1, 2006 11:41 AM by Jan Arend Jansen

    New scoping of EntityManager and SessionBeans

    Jan Arend Jansen Newbie

      Is it just me, or is the new (RC4) way of default JNDI names for scoping EntityManagers and SessionBeans plain ugly?

      EntityManagers are scoped with their jar name, something like

      @PersistenceContext (name="../domain.jar/em)

      I think this is wrong, because I don't want to have the name of the jar file in my code. That is a deployment issue, not a coding issue.

      Same for SessionBeans. They are scoped with their EAR file name:
      new InitialContext().lookup("myear/myserviceBeanImpl/local")

      This has two aspects I don't like very much:
      1. I don't want to have the name of my ear file in the code (see previous argument)
      2. The name of the SessionBean is the name of the implementing bean, where I would expect the name of the interface instead.

      I know that you can work around this naming by using @JNDI annotations, but I liked the default naming in the previous release better.

      Anyone have an opinion on this?

        • 2. Re: New scoping of EntityManager and SessionBeans
          Bill Burke Master

          Scoping is spec mandated, nothing we can do about it. In fact, I'm not even sure you can legally reference a PU packaged within an EJB-JAR with the "../foo.jar#PU" syntax. Repackage your persistence units into their own jar separate from EJBs and you don't have to use that ugly syntax.

          As for the EJB default JNDI names? Yes, I liked the old syntax too but it didn't work well out of the box when you use the same interface name in multiple EJBs or versioned the EJB in different EARs. If you think about it, the EAR syntax is analogous to the WAR file name being used as the root context in a URL. If you don't like the default names, you can change it in jboss.xml or with the @Remote/@LocalBinding annotations.

          • 3. Re: New scoping of EntityManager and SessionBeans
            Jan Arend Jansen Newbie

            Bill, I understand your point on the scoping being spec mandated. But the spec is not final yet, I believe, so do you think that this should be repared in the final spec? Or do you see benifits of scoping to the JAR instead of the EAR level?

            Your suggestion on repacking sound a lot like what I've done in my project (a core.jar that contains the EJBs and a domain.jar that contains the PersistenceUnit and the entity beans. The PU is scoped to the domain.jar so in the domain.jar I'm fine. But the EJB package also needs to reference the PU and then I need to scope it to the domain.jar, right? Or am I missing something?

            Best regards,
            Jan Arend Jansen

            • 4. Re: New scoping of EntityManager and SessionBeans
              Bill Burke Master

               

              "jajansen" wrote:
              Bill, I understand your point on the scoping being spec mandated. But the spec is not final yet, I believe, so do you think that this should be repared in the final spec? Or do you see benifits of scoping to the JAR instead of the EAR level?


              Well, EJB-JAR classes may be isolated. Also, EJB-JARs may be developed separately and maybe contain the same persistence unit names. Same goes with pu's deployed within a WAR. A WAR is *definately* isolated from all other EJBs and WARs. In JBoss, EJB jars are not deployed in an isolated classloader, so this point is moot, but this may not be the same in other app servers.

              Your suggestion on repacking sound a lot like what I've done in my project (a core.jar that contains the EJBs and a domain.jar that contains the PersistenceUnit and the entity beans. The PU is scoped to the domain.jar so in the domain.jar I'm fine. But the EJB package also needs to reference the PU and then I need to scope it to the domain.jar, right? Or am I missing something?
              
              Best regards,
              Jan Arend Jansen


              • 5. Re: New scoping of EntityManager and SessionBeans
                Jan Arend Jansen Newbie

                Ok, guess I have to live with it then ;-)

                Thanks for the elaboration.