Java – best practices for providing entitymanager in OSGi applications

I've read a lot of other questions about my problem on stack overflow, but I can't find a suitable solution

I developed an OSGi application (Equinox) and used JPA (eclipse link) Now I ask for the best way to get the entitymanager in the bundle that needs it When I publish an entitymanagerfactory as a service and use it to obtain an entitymanger, I must provide persistence. In each bundle that uses an entitymanager xml. When I write a utility class that shares an entitymanger instance and publishes it as a service, I'm afraid of thread synchronization problems

Are there any best practices to provide entitymanager when using OSGi and JPA?

thank you

Bear

Solution

In eclipse link, when used in OSGi, you must add "JPA persistence units: mypersistence unit" to persistence Manifest.xml package MF to declare in which package persistence can be found xml. Eclipse link will search for this declaration and will use the bundle's classloader to get persistence xml. You can then publish the entitymanagerfactory as a service, and you do not need to use the service to share persistence. XML in each bundle xml. But I think this only applies to eclipse link

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>