Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [gemini-dev] JPA + EclipseLink in OSGi environment

Hi Eugen,

We generally ask users to post to the user forum so that the answers are accessible to others.

         http://www.eclipse.org/forums/index.php?t=thread&frm_id=153

Thanks,
-Mike

On 30/11/2011 11:19 AM, Eugen Reiswich wrote:
Hi folks, 

I've been recommended to post my problem in this forum, I hope this is the right place. I try to run JPA + EclipseLink in an OSGi environment with a specific architecture:

*.domain.customer // business objects
*.domain.account

*.service.customer
*.service.account

*.service.customer.dao
- orm.xml
- persistence.xml

*.service.account.dao
- orm.xml
- persistence.xml

*.service.dao_jpa // OSGi service providing the DB credentials in a single place
- IDatabaseCredentialsService

I try to avoid redundant database credentials within the two persistence.xml files using the EntityManagerFactoryBuilder which retrieves db-credentials from my own IDatabaseCredentialsService. But this solution seems to produce a lot of code and one has to be aware of race conditions. 

private void createEntityManagerFactory() {
assert emfBuilder != null : "emfBuilder != null";
assert dbCredentials != null : "dbCredentials != null";

Map<String, String> dbCredentioals = dbCredentials.getDBCredentioals();
entityManagerFactory = emfBuilder
.createEntityManagerFactory(dbCredentioals);

createCustomer();
}

public void bindDBConnectionService(IDatabaseCredentialsService dbService) {
dbCredentials = dbService;
if (emfBuilder != null) {
createEntityManagerFactory();
}
}

public void bindEMFBuilder(EntityManagerFactoryBuilder builder) {
emfBuilder = builder;
if (dbCredentials != null) {
createEntityManagerFactory();
}
}

I hope you can help me and point me to a better and simpler solution.

Eugen




_______________________________________________
gemini-dev mailing list
gemini-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/gemini-dev

Back to the top