Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Your description of the problem is a little sloppy:</p> <blockquote> <p>persistent.xml is presnt only in project A.Do i need to place persistent.xml in project A too?</p> </blockquote> <p>I take it you mean: <em>persistence.xml is present only in project B. Do I need to place persistence.xml in project A too?</em></p> <p>What exactly is the setup? Are both projects deployed to the same server? Are they on different servers? Is project A accessing a remote session bean of project B? What projects are we talking about? Web projects, EJB projects? EAR projects with both Web and EJB projects in them?</p> <p>I don't think it's supported that you ship an entity manager from one application to the other. The idea is that a client calls a remote bean, then this remote bean obtains a local entity manager, does some work with it and returns the results. If A is your client, then A certainly <strong>does not</strong> need to have a local persistence.xml.</p> <p>Your problem might well be that the entity manager you're after is simply not available under the name you think it is. <code>java:comp/env/persistence</code> obviously doesn't exist. Normally an entity manager doesn't appear automatically in JNDI. If B was a servlet, you would need something like this:</p> <pre><code>&lt;persistence-context-ref&gt; &lt;persistence-context-ref-name&gt;persistence&lt;/persistence-context-ref-name&gt; &lt;persistence-unit-name&gt;yourpu&lt;/persistence-unit-name&gt; &lt;/persistence-context-ref&gt; </code></pre> <p>If B was an EJB session bean, you need something like this:</p> <pre><code>@Stateless @PersistenceUnit(name="persistence", unitName="yourpu") public class BBean implements BRemoteInterface { // some code here... } </code></pre> <p>After this, the entity manager would be available under <code>java:comp/env/persistence</code>, but <strong>only</strong> when the JNDI lookup is being initiated from that servlet or bean. java:comp/env is a relative context, that is different for each location that a lookup is done on it.</p> <p>The least you could do is simply printing your <code>java:comp/env</code> context from B and see what's in there exactly. See this simple example how to do such printing: <a href="http://tripoverit.blogspot.com/2007/03/print-jndi-tree.html" rel="nofollow">http://tripoverit.blogspot.com/2007/03/print-jndi-tree.html</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload