Skip to main content

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

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



Back to the top