Using Gemini DBAccess/JPA in services [message #989227] |
Wed, 05 December 2012 10:02 |
Ronald Joseph Messages: 10 Registered: December 2012 |
Junior Member |
|
|
Hello,
I want to use Gemini DBAccess/JPA in a service.
For that I have created a plugin which will act as a service.
Dependencies as I have
org.eclipse.gemini.jpa;bundle-version="1.1.0",
org.eclipse.gemini.dbaccess.derby;bundle-version="1.1.0",
org.apache.derby;bundle-version="10.5.1",
com.hds.persistence.bundle;bundle-version="1.0.0",
org.eclipse.gemini.ext.di;bundle-version="1.0.0" .
In the META-INF/MANIFEST.MF file
Meta-Persistence: META-INF/persistence.xml
JPA-PersistenceUnits: hds
are registered.
The file META-INF/persistence.xml exists. The EMF also be created accordingly.
In my service implementation, I use the following to get a reference to the EentityManager:
@Inject
@GeminiPersistenceContext (unitName = "hds")
protected EntityManager em;
In the file OSGI-INF/component.xml I've also added a reference to the EMF.
<reference name="EMF"
interface="javax.persistence.EntityManagerFactory"
cardinality="1..1"
target="(osgi.unit.name=hdsPersistence)"
policy="dynamic"/>
See http://www.eclipse.org/forums/index.php/m/837592/?srch=gemini+jpa+service#msg_837592.
When I start the service, however, is no EM was injected.
If I
@Inject
@GeminiPersistenceContext (unitName = "hds")
protected EntityManager em;
for example, in a handler use, coupled with a CMD, the EM is injected correctly.
Can anyone tell me what needs to be done in order to use Gemini in a service?
The service is to be used in UI parts to encapsulate the access to the data.
Sorry for my English.
Greeting for Germany.
Ronald
|
|
|
|
|
|
|
Re: Using Gemini DBAccess/JPA in services [message #989476 is a reply to message #989360] |
Thu, 06 December 2012 11:53 |
Ronald Joseph Messages: 10 Registered: December 2012 |
Junior Member |
|
|
Hello Mike,
it's exasperating.
I have looked at the thread and think that it does not fit. It is the basis of Gemini.Ext.DI implementation. The way I see it, I can here all the possible values that I can use in the persistence.xml.
I do not think it helps me more.
I want to try again to outline my problem.
First: I have a plugin that provides @Entity. It also contains the META-INF/persistence.xml and the matching entry in the MANIFEST.MF.
Second: I want to implement a plugin that provides services to the application (read, write, search for Entity, etc.). The interface of the application are provided so that this plugin interface methods.
Thirdly, when the activation of the service Plugings I would get the reference to the javax.persistence.EntityManager(Factory).
The first plugin (the one with the @Entity) is found when the application and it seems that the appropriate services are registered.
The second plugin I implemented a bundle Activator, which has a service tracker for javax.persistence.EntityManagerFactory. The method addingService (ServiceReference reference) returns the reference.
In the service implementation I have a method activate (Component context) implemented, the service searches for a reference, which I have set in the OSGI-INF/compoments.xml:
<reference name="EMF"
interface="javax.persistence.EntityManagerFactory"
cardinality="1..1"
target="(osgi.unit.name=hdsPersistence)"
policy="dynamic"/>
Here is a fragment from the Bundle-Activator:
@Override
public void start (BundleContext context) throws Exception {
log.info ("HDS Service DBAccess starting");
ctx = context;
dsfTracker = new ServiceTracker (
ctx,
EntityManagerFactory.class.getName (),
this);
dsfTracker.open ();
log.info (
"HDS Service DBAccess started ctx:=" + ctx + ", dsfTracker:=" + dsfTracker);
log.info ("HDS Service DBAccess started");
}
@Override
public Object addingService (ServiceReference reference) {
log.info ("addingService (" + reference + ") ...");
Bundle b = reference.getBundle();
Object service = b.getBundleContext().getService(reference);
String unitName = (String) reference.getProperty(EntityManagerFactoryBuilder.JPA_UNIT_NAME);
log.info ("b:=" + b);
log.info ("service:=" + service);
log.info ("unitName:=" + unitName);
return service;
}
Here is a fragment from the Service-Activator:
protected void activate (ComponentContext context) {
System.out.println (getClass ().getName () + ".activate (" + context + ")...");
Object obj = context.locateService ("EMF");
System.out.println (" locateService (\"EMF\"):=" + obj);
if (obj instanceof EMFServiceProxyHandler) { // <== ClassNotFoundException here
em = (EntityManager) ((EMFServiceProxyHandler) obj).createEMF (null);
}
if (obj instanceof EntityManagerFactory) {
em = ((EntityManagerFactory) obj).createEntityManager ();
}
System.out.println (" em:=" + em);
System.out.println (getClass ().getName () + ".activate (" + context + ") FINISHED");
}
When I start the application I receive in this method a ClassNotFoundException (see mark).
I have somewhere a mistake? Or a trifle forgotten?
Is there a way, the EntityManager (Factory) in the activation of the service implementation to resolve somehow the OSGI framework?
If so how?
Greetings form Germany.
Ronald
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04156 seconds