You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomee.apache.org by David Jencks <da...@yahoo.com> on 2010/04/20 19:30:49 UTC

Would using jndi more directly for cmp persistence-ref cause problems?

I have cmp 2 beans working in geronimo trunk with the following small change to how the cmp engine finds its EM:

Index: container/openejb-core/src/main/java/org/apache/openejb/core/cmp/jpa/JpaCmpEngine.java
===================================================================
--- container/openejb-core/src/main/java/org/apache/openejb/core/cmp/jpa/JpaCmpEngine.java      (revision 935765)
+++ container/openejb-core/src/main/java/org/apache/openejb/core/cmp/jpa/JpaCmpEngine.java      (working copy)
@@ -28,6 +28,7 @@
 import javax.ejb.EntityBean;
 import javax.ejb.FinderException;
 import javax.ejb.RemoveException;
+import javax.naming.InitialContext;
 import javax.naming.NamingException;
 import javax.persistence.EntityManager;
 import javax.persistence.PersistenceException;
@@ -90,7 +91,8 @@
     private EntityManager getEntityManager(CoreDeploymentInfo deploymentInfo) {
         EntityManager entityManager = null;
         try {
-            entityManager = (EntityManager) deploymentInfo.getJndiEnc().lookup("java:comp/env/" + CMP_PERSISTENCE_CONTEXT_REF_NAME);
+            entityManager = (EntityManager) new InitialContext().lookup("java:comp/env/" + CMP_PERSISTENCE_CONTEXT_REF_NAME);
         } catch (NamingException ignroed) {
         }


This might be marginally slower but since we're about to go talk to a database I don't think creating a couple extra jndi objects will be really noticeable.

Anyone have a problem with me committing this change?

thanks
david jencks


Re: Would using jndi more directly for cmp persistence-ref cause problems?

Posted by David Blevins <da...@visi.com>.
On Apr 20, 2010, at 10:30 AM, David Jencks wrote:

> I have cmp 2 beans working in geronimo trunk with the following  
> small change to how the cmp engine finds its EM:
>
> Index: container/openejb-core/src/main/java/org/apache/openejb/core/ 
> cmp/jpa/JpaCmpEngine.java
> ===================================================================
> --- container/openejb-core/src/main/java/org/apache/openejb/core/cmp/ 
> jpa/JpaCmpEngine.java      (revision 935765)
> +++ container/openejb-core/src/main/java/org/apache/openejb/core/cmp/ 
> jpa/JpaCmpEngine.java      (working copy)
> @@ -28,6 +28,7 @@
> import javax.ejb.EntityBean;
> import javax.ejb.FinderException;
> import javax.ejb.RemoveException;
> +import javax.naming.InitialContext;
> import javax.naming.NamingException;
> import javax.persistence.EntityManager;
> import javax.persistence.PersistenceException;
> @@ -90,7 +91,8 @@
>     private EntityManager getEntityManager(CoreDeploymentInfo  
> deploymentInfo) {
>         EntityManager entityManager = null;
>         try {
> -            entityManager = (EntityManager)  
> deploymentInfo.getJndiEnc().lookup("java:comp/env/" +  
> CMP_PERSISTENCE_CONTEXT_REF_NAME);
> +            entityManager = (EntityManager) new  
> InitialContext().lookup("java:comp/env/" +  
> CMP_PERSISTENCE_CONTEXT_REF_NAME);
>         } catch (NamingException ignroed) {
>         }
>
>
> This might be marginally slower but since we're about to go talk to  
> a database I don't think creating a couple extra jndi objects will  
> be really noticeable.
>
> Anyone have a problem with me committing this change?

As discussed on IRC, it's fine as a temporary change to get more TCK  
tests to run.

-David