Using JPA without publishing the persistence unit with Gemini JPA [message #1033868] |
Thu, 04 April 2013 14:36  |
Eclipse User |
|
|
|
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] by 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  |
Eclipse User |
|
|
|
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
|
|
|
Powered by
FUDForum. Page generated in 0.03068 seconds