Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[eclipselink-users] JPA & OSGi

Here are some initial thoughts for discussion ...

Clients could obtain an EntityMangerFactory through an OSGi service. Something like:

public interface IJPAService
{
  EntityManagerFactory createEntityManagerFactory(String unitName);
EntityManagerFactory createEntityManagerFactory(String unitName, Map<String, String> properties);
}

IJPAService basically replaces javax.persistence.Persistence. The JPA implementation would register an implementation of the service as an OSGi service:

public class Activator implements BundleActivator
{
  public void start(BundleContext context)
  {
context.registerService(IJPAService.class.getName(), new JPAService(), null);
  }
}

public class JPAService implements IJPAService
{
  ...
}

Clients would access the service using the standard:

public class Activator implements BundleActivator
{
  public void start(BundleContext context)
  {
ServiceReference ref = context.getServiceReference(IJPAService.class.getName());
    IJPAService service = (IJPAService) context.getService(ref);
  }
}

Actually, a service tracker is the proper way to get the service, but that's not important for this discussion.

This does not prevent a user from using javax.persistence.Persistence. Should this be allowed, or should that bootstrapping mechanism be disabled? If we want this to be allowed, it needs to be modified to not use the context classloader. My preference would be to remove it from the API, or possibly have it throw UnsupportedOperationException.

The JPA API would be in it's own bundle (javax.persistence ??) separate from the implementation (org.eclipse.eclipselink.jpa ??).

What should happen if the implementation bundle is stopped and there are active EntityManagers?

Bryan



Back to the top