cancel
Showing results for 
Search instead for 
Did you mean: 

how to find PersistenceUnit in JNDI

former_member190457
Contributor
0 Kudos

Hi developers,

In my EE5 application I have developed an EJB DC with JPA facet.

In persistence.xml I have defined a persistence unit called TABLE

When I try to find this name in NWA -> JNDI browser (in classes, context or object), I can find nothing.

I need this to perform JNDI lookup of the EntityManager's Persistence Unit from a DC other than the one the persistence unit is deployed in.

Can someone please help?

Thanks, regards

Vincenzo

Accepted Solutions (1)

Accepted Solutions (1)

adrian_goerler
Active Participant
0 Kudos

Hi Vincenzo,

firstly, you need to bind the persistence unit into JNDI. You can do so either by placing the @PersistenceUnit annotation on e.g. a session bean. The member "name" determines the name under which you can look up the persistence unit in your local JNDI space. E.g.

@PersistenceUnit(unitName="myUnit", name="myLookUpName")

@Stateless

public class MyBean {

...

Context ctx = new InitialContext();

EntityManagerFactory emf = (EntityManagerFactory)ctx.lookup("java:comp/env/myLookUpName");

Alternatively, you can bind the persistence unit into the JDNI using the persistence-unit-ref tag of the ejb-jar.xml or the web.xml:

<persistence-unit-ref>

<persistence-unit-ref-name>myLookUpName</persistence-unit-ref-name>

<persistence-unit-name>myUnit</persistence-unit-name>

</persistence-unit-ref>

I hope this helps.

-Adrian

former_member190457
Contributor
0 Kudos

Hi Adrian,

thanks for your quick reply.

The point is, the only way I managed to have JNDI lookup working in SAP AS is to use in my code the complete JNDI object name string as retrieved from JNDI browser in NWA.

This works great for EJBs, proxies and so on. So now I would like to find the persistence unit in JNDI as well.

How can that be done?

Thanks, regards

Vincenzo

adrian_goerler
Active Participant
0 Kudos

Do I understand correctly that you have tried out what I suggested and it does not work?

Is the other DC you intend to look up the EntityManagerFactory part of the same application?

-Adrian

former_member190457
Contributor
0 Kudos

Hi Adrian,

what you suggest is exactly what the specification mandates and I tried it first thing.

However on SAP AS this procedure does not work for me. Did you manage to have it working?

In my scenario the EJB is not in the same EJB DC or even EAR DC of the persistence unit.

In addition, actually I would like to look up the EntityManager and not the EntityManagerFactory, can that be done?

Thanks, regards

Vincenzo

adrian_goerler
Active Participant
0 Kudos

Hi,

the procedure is working fine if you look up the entity manager [factory] in the same application. Looking up an entity manager from a different application won't work this way as you are not in the same local JNDI context.

I could imagine that entity managers and entity manager factories are simply not avaliable in the global JNDI. I'll double check this.

You could try calling a session bean in the application containing the persistence unit to obtain an entity manager [factory] from.

-Adrian

former_member190457
Contributor
0 Kudos

Hi Adrian,

interestingly enough, a similiar behavior happens when trying to lookup JAX-WS web service proxies from an EAR other than the one they are deployed in.

Actually the proxy is not mapped on the global JNDI unless it is used via @WebServiceRef, by another EJB of the same EAR for instance.

In that case you can find it in JNDI browser and look it up from wherever you wish.

The path of the proxy will be something like:


wsclients/proxies/<vendor>/<EJB DC>/<EJB DC>_EJB/<Bean name>/<fully qualified bean name>/<name of the variable in which the proxy is injected>

Do you know if there is a cleaner way to look up WS proxies from an arbitrary code location?

Thanks again

Vincenzo

Edit: I have opened a new thread concerning this latter question.

Edited by: VINCENZO TURCO on Jul 16, 2010 12:09 PM

Answers (0)