cancel
Showing results for 
Search instead for 
Did you mean: 

EntityManagerFactory jndi lookup (JPA)

Former Member
0 Kudos

Hi

How can i get EntityManagerFactory jndi name in the NW CE 7.1.

I cant find it on jndi browser tab in the SAP NetWeaver Administrator.

My persistence.xml contains the following entries

<persistence-unit name="test1" transaction-type="JTA">

<jta-data-source>testDataSource</jta-data-source>

<class>test.TestEntity</class>

<jta-data-source>

<persistence-unit>

how should i reffer to it in my java code:

(EntityManagerFactory) context.lookup("????")

My class is not a container managed object so annotation @Persistence want work in that case, so i guess the only way to get EntityManagerFactory is through jndi lookup.

right?

Br

PF

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi, PaFaWa,

To obtain a container-managed EM instance, you use the @PersistenceContext annotation to have the EJB container inject an EM instance into the application component using dependency injection.

To obtain an application-managed EM instance, you must first obtain an entity manager factory instance.

Please, have a look at [THIS|http://help.sap.com/saphelp_nwce10/helpdata/en/45/0029b3515224dee10000000a114a6b/frameset.htm] link for more information.

Hope that helps!

Regards,

Yordan

Former Member
0 Kudos

Hi

I'm doing this in a class that is a pojo class - so its not a container managed class like ejb for instance, therefore i cant use dependency injection, therefore i must use jndi lookup.

I cant use jndi lookup since i dont know the EnitytManagerFactory's jndi name.

Br

PF

Former Member
0 Kudos

Hi

To be more precise, i think it all comes to finding a way to bind EntityManagerFactory into a EJB's naming context.

Br

PF

ekaterinamitova
Advisor
Advisor
0 Kudos

Hi,

Why don't you try using the EJB lookup scheme. There is more information in this article: https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/b0d58c0a-b2ce-2a10-8082-a3dda343...

Best regards,

Ekaterina

Former Member
0 Kudos

Hi

Thx - the idea sounds very interesting, but applied to this problem seems like forcing opened doors.

I think that all i need is to find Enity|managerFactory jndi name which must be somewhere there in the jndi naming tree.

Perhaps an extra property in the persistence.xml file is needed to set it , like it's done in jboss.

Br

PF

Vlado
Advisor
Advisor
0 Kudos

>

> To be more precise, i think it all comes to finding a way to bind EntityManagerFactory into a EJB's naming context.

>

You're right. For that you have to define a reference to the EMF - either via annotation or in the ejb-jar.xml. For example:


@Stateless
@PersistenceUnit(name = "persistence/myLookupName", unitName = "test1")
public class MySessionBean ...

Then you can use JNDI lookup in each and every POJO class that executes on behalf of the MySessionBean component.

HTH!

\-- Vladimir

Former Member
0 Kudos

Hi

Thx, again - this is exactly what i was looking for. Good to have Your support.

Br

PF

Former Member
0 Kudos

Hi

Will it be also visible for other jars in the same ear, if not how can it make visible.

Br

PF

Vlado
Advisor
Advisor
0 Kudos

It's available only to the EJB for which it's defined and other helper (POJO) classes that execute in this EJB's context. In order to be available to other EJBs, in the same or other jars, you have to define a similar reference for them too.

Cheers,

\-- Vladimir

Former Member
0 Kudos

Hi,

Can you please kindly guide me how should I construct my lookup string in POJO class, if I have the annotations as mentioned in your post:

@Stateless

@PersistenceUnit(name = "persistence/myLookupName", unitName = "test1")

public class MySessionBean ...

Thanks & Regards,

Goh

Answers (0)