Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Gemini » Using JPA without publishing the persistence unit with Gemini JPA
Using JPA without publishing the persistence unit with Gemini JPA [message #1033868] Thu, 04 April 2013 14:36 Go to next message
Jochen Seeber is currently offline Jochen Seeber
Messages: 1
Registered: April 2013
Junior Member
Hi,

I am trying to create a "private" persistence unit in my bundle that I do not want published as a service. For this reason, I'm not using the "Meta-Persistence" element in my manifest, but trying to create the EntityManager the non-OSGi way:

EntityManager em = Persistence.createEntityManagerFactory("unit").createEntityManager();

However, since OSGi's JPA replaces the PersistenceProvider(Resolver) and only does a service lookup, the creation of the EntityManagerFactory fails.

My question now is: What is the right way in Gemini JPA to create a "private" EntityManagerFactory that is not exposed to other bundles, and use it in the bundle?

If this is not possible, how can I create an EntityManagerFactory using "Meta-Persistence" and use it in the same module (since the EMF is only registered by Gemini after the bundle was started).

Regards,
Jochen

[Updated on: Sat, 06 April 2013 13:50]

Report message to a moderator

Re: Using JPA without publishing the persistence unit with Gemini JPA [message #1036798 is a reply to message #1033868] Mon, 08 April 2013 16:43 Go to previous message
Mike Keith is currently offline Mike Keith
Messages: 211
Registered: July 2009
Senior Member
Hi Jochen,

Do you not want the EMF service in the registry simply because you don't want someone to stumble into it, or because you want it completely isolated from all other bundles so that it would be impossible for them to use it.

In the first case you could just remove the DB connection info from the persistence descriptor. This will cause the EMFBuilder to be registered, but not the EMF. Then you could pass the DB props into the Persistence.createEntityManagerFactory() call and it will look for the builder instead of an EMF service and use it to create an EMF for you.

The second case is a bigger issue. Applications that want strict isolation typically use service permissions with an active security manager. Take a look at service permissions as well as the Permission Admin service.

-Mike
Previous Topic:Maven repository for Gemini projects
Next Topic:[Solved]Handling subclasses of Entities (Cross Bundle Workaround)
Goto Forum:
  


Current Time: Fri Aug 22 11:58:33 EDT 2014

Powered by FUDForum. Page generated in 0.01616 seconds