title: JPA invalid user/password inside multithreads
body: <p>I'm having an issue with JPA in multithreads application. I'm using JPA proxy authentication to access the database. Everything runs fine in session beans but when in java thread <code>run()</code> method, I cannot use <code>@EJB</code> so I use Initialcontext to look up the bean. When the program executes, I'm getting invalid username/password; logon denied. </p>
  
  <pre><code>@Stateless
  public class MyDAO{
       @PersistenceContext(name="myPU")
       private EntityManager em;
       public MyEntity getData(String id){
           return em.find(MyEntity.class, id);
       }
       @AroundInvoke
       public Object setSessionUser(InvocationContext ctx){
         if(ctx.getTarget() instanceof MyDAO){
           Map properties = new HasMap();
           properties.put("eclipselink.oracle.proxy-type", OracleConnection.PROXYTYPE_USER_NAME);
           properties.put(OracleConnection.PROXY_USER_NAME, "myusername");
           properties.put("eclipselink.jdbc.exclusive-connection.mode", "Always");
           properties.put("eclipselink.jdbc.exclusive-connection.is-lazy", "false");
           ((org.eclipse.persistence.internal.jpa.EntityManagerImpl)em.getDelegate()).setProperties(properties);
           }
           return ctx.proceed();
      }
  }
  </code></pre>
  
  <p>inside run();</p>
  
  <pre><code>@Override
  public void run(){
     ...
     MyDAO dao = (MyDAO) new InitialContext().lookup("java:module/...");
     EntityObject obj = dao.getData("123456");
     ...
  }
  </code></pre>