Problem with JNDI

I have code that uses JNDI. This piece of code looks like this:

EntityManager createEM(String JNDI ){

  EntityManager em = null;
   try{
   InitialContext ic = new InitialContext();
   em = (EntityManager) ic.lookup(JNDI);
   return em;
   }
 catch (Exception ex){
   LOG.Error("error in creating em");
   ex.printStackTrace();

}

}

Now I get the error. The control is part of a catch block.

javax.naming.NameNotFoundException: Name comp/env/persistence not found in context "java:".
[12/28/10 15:51:07:086 GMT+05:30] 00000081 SystemErr     R  at com.ibm.ws.naming.ipbase.NameSpace.getParentCtxInternal(NameSpace.java:1837)
[12/28/10 15:51:07:086 GMT+05:30] 00000081 SystemErr     R  at com.ibm.ws.naming.ipbase.NameSpace.lookupInternal(NameSpace.java:1166)
[12/28/10 15:51:07:086 GMT+05:30] 00000081 SystemErr     R  at com.ibm.ws.naming.ipbase.NameSpace.lookup(NameSpace.java:1095)
[12/28/10 15:51:07:086 GMT+05:30] 00000081 SystemErr     R  at com.ibm.ws.naming.urlbase.UrlContextImpl.lookup(UrlContextImpl.java:1233)
[12/28/10 15:51:07:086 GMT+05:30] 00000081 SystemErr     R  at com.ibm.ws.naming.java.javaURLContextImpl.lookup(javaURLContextImpl.java:394)
[12/28/10 15:51:07:086 GMT+05:30] 00000081 SystemErr     R  at com.ibm.ws.naming.java.javaURLContextRoot.lookup(javaURLContextRoot.java:214)
[12/28/10 15:51:07:086 GMT+05:30] 00000081 SystemErr     R  at com.ibm.ws.naming.java.javaURLContextRoot.lookup(javaURLContextRoot.java:154)
[12/28/10 15:51:07:086 GMT+05:30] 00000081 SystemErr     R  at javax.naming.InitialContext.lookup(Unknown Source)

I have 2 projects: A and B.Now project B has the above method, and from project A I call mehod from project B.persistent.xml is presnt only in project A. Do I need to place persistent.xml in Project A too? I also get the following exception

 javax.naming.NameNotFoundException: Name comp/env/persistence not found in context "java:".

What could be the reason. Using websphere.

+1
source share
3 answers

Your description of the problem is a bit messy:

persistent.xml is presnt only in project A. Do I also need to place persistent.xml in project A?

: persistence.xml B. persistence.xml A?

? ? ? A bean B? ? -, EJB? EAR Web EJB ?

, , . , bean, bean , . A , A persistence.xml.

, , , , , . java:comp/env/persistence, , . JNDI. B , - :

<persistence-context-ref>
    <persistence-context-ref-name>persistence</persistence-context-ref-name>
    <persistence-unit-name>yourpu</persistence-unit-name>
</persistence-context-ref>

B EJB bean, - :

@Stateless
@PersistenceUnit(name="persistence", unitName="yourpu")
public class BBean implements BRemoteInterface {
    // some code here...
}

java:comp/env/persistence, , JNDI bean. java: comp/env - , , .

java:comp/env B , . . , ​​: http://tripoverit.blogspot.com/2007/03/print-jndi-tree.html

+2

persistence websphere?

, u 'persistence'

0

You can debug the application running on the web page. It can be done. I suggest you run the application in debug mode and break point at jndi lookup point, and then you can poll the jndi context state.

0
source

Source: https://habr.com/ru/post/1784246/


All Articles