Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » EclipseLink + RCP + OSGI Service: No Persistence provider for EntityManager
EclipseLink + RCP + OSGI Service: No Persistence provider for EntityManager [message #684777] Thu, 16 June 2011 07:50 Go to next message
Eclipse UserFriend
Originally posted by: Karsten Voigt

Hi,

I have problem using EclipseLink within a RCP application....

I created a PlugIn that contains the persistence.xml and all the
required configuration stuff. This plugin provides an OSGI service for
accessing the database via JPA. During service activation the
EntityManagerFactory is created.

Everything works fine as long as I run my application as application in
eclipse.

Now I created a product definition based on that application launch
configuration and I get this exception:

Caused by: javax.persistence.PersistenceException: No Persistence
provider for EntityManager

(Switching back to 'normal' application start everything works fine.)

Any hints that might be the problem? I've already checked several
examples, but I can't find my mistake.

Thanks.
Karsten
Re: EclipseLink + RCP + OSGI Service: No Persistence provider for EntityManager [message #684841 is a reply to message #684777] Thu, 16 June 2011 10:39 Go to previous messageGo to next message
Jens Mising name is currently offline Jens Mising nameFriend
Messages: 12
Registered: March 2010
Location: Berlin
Junior Member
Can you post a full stacktrace to that exception?

Are you sure all plugins are there (e.g. the javax.persistence jar)?

Maybe this has to do with ClassLoading?
I ran into a similar problem and ended up using a PersistenceProvider from an osgi package that is capable of loading classes in an osgi environment.

However you said that it runs ok within eclipse target platform which is also OSGI. So I guess, I don't really know. Maybe you can provide some more details.
(no subject) [message #684857 is a reply to message #684777] Thu, 16 June 2011 10:39 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: <forums-noreply

Can you post a full stacktrace to that exception?

Are you sure all plugins are there (e.g. the javax.persistence jar)?

Maybe this has to do with ClassLoading?
I ran into a similar problem and ended up using a PersistenceProvider from an osgi package that is capable of loading classes in an osgi environment.

However you said that it runs ok within eclipse target platform which is also OSGI. So I guess, I don't really know. Maybe you can provide some more details.
Re: (no subject) [message #696612 is a reply to message #684857] Thu, 14 July 2011 11:59 Go to previous messageGo to next message
MichaelS  is currently offline MichaelS Friend
Messages: 9
Registered: July 2011
Junior Member
I have a similar problem. I have a JPA-Plugin in which is the persitence.xml located(in src/meta-inf) and there is an adapter class which has the methods for the entity management(load, save, remove etc.). second i have an main plugin. there are the entities. In these plugin i get the adapter class of the JPA-plugin by using the extension point. The third plugin is the lib plugin. There are all libs are needed(eclipselink.jar, javax.persistence.jar...). The lib plugin is a required plugin of the main plugin and of the jpa plugin.
Now i run the RCP application and get the error 'javax.persistence.PersistenceException: No Persistence provider for EntityManager'.

It seems that the persistence.xml is not found. Because i have manipulate it so that it isn't a correct persistence.xml:

<?xml version="1.0" encoding="UTF-8"?>
<persistence >
   <sdrf34 4></sdrf34>
</persistence>




There should an incorrect xml error throwing. But it isn't so. The same error like before came. So i gueess the persistence.xml isn't load to the context.

here are my correct persitence.xml:

<?xml version="1.0" encoding="UTF-8"?>
<persistence>
   	<persistence-unit name="de.robotron.eprofiler.persistence.jpa">
		<provider>org.eclipse.persistence.jpa.osgi.PersistenceProvider</provider>
		<class>de.robotron.eprofiler.series.generic.AbstractITraversable</class>
		<class>de.robotron.eprofiler.rules.AbstractRuleSet</class>
		<class>de.robotron.eprofiler.rules.profile.CombinedProfile</class>
		<class>de.robotron.eprofiler.rules.connection.ConnectionSpecifier</class>
		<class>de.robotron.eprofiler.rules.cost.CostUnit</class>
		<class>de.robotron.eprofiler.rules.cost.CostUnitEntry</class>
		<class>de.robotron.eprofiler.series.generic.GenericCustomer</class>
		<class>de.robotron.eprofiler.series.generic.GenericLine</class>
		<class>de.robotron.eprofiler.rules.holiday.HolidayRegion</class>
		<class>de.robotron.eprofiler.rules.profile.LengthOfDayProfile</class>
		<class>de.robotron.eprofiler.rules.line_settings.LineSettings</class>
		<class>de.robotron.eprofiler.rules.profile.ListProfile</class>
		<class>de.robotron.eprofiler.rules.profile.PeriodicProfile</class>
		<class>de.robotron.eprofiler.rules.profile.ProfileEntry</class>
		<class>de.robotron.eprofiler.rules.RuleEntry</class>
		<class>de.robotron.eprofiler.series.generic.PrognoseLine</class>
		<class>de.robotron.eprofiler.series.generic.StandardLine</class>
		<class>de.robotron.eprofiler.series.generic.StandardMeteringPoint</class>
		<class>de.robotron.eprofiler.series.generic.StandardNetworkAccessPoint</class>
		<class>de.robotron.eprofiler.rules.tarif.TarifArt</class>
		<class>de.robotron.eprofiler.rules.tarif.TarifPeriode</class>
		<class>de.robotron.eprofiler.rules.tarif.TarifTag</class>
		<class>de.robotron.eprofiler.rules.tarif.TarifProfil</class>
		<class>de.robotron.eprofiler.rules.tarif.TarifTagPeriode</class>
		<class>de.robotron.eprofiler.series.generic.VirtualLine</class>
		<class>de.robotron.eprofiler.series.generic.GenericFolder</class>
		<class>de.robotron.eprofiler.series.generic.GenericSettings</class>
		<class>de.robotron.eprofiler.series.generic.GenericDBConnection</class>
		<class>de.robotron.eprofiler.view.prognose.mathematical.model.PrognoseMap</class>
		<properties>
			<property name="eclipselink.ddl-generation.output-mode" value="sql-script"></property>
			<property name="eclipselink.ddl-generation" value="drop-and-create-tables"></property>
		</properties>
	</persistence-unit>
</persistence>


and my adapter class:

private EntityManagerFactory getEntityManagerForConnection(String connectionName){
		
		if(emfactories.containsKey(connectionName)){
			return emfactories.get(connectionName);
		}else{
			PersistenceProvider provider = new PersistenceProvider();
			ConnectionSpecifier cons = OptionConnection.getInstance().getConnectionSpecifierByName(connectionName);
			Map<String, Object> overrides = new HashMap<String, Object>();
//			overrides.put(PersistenceUnitProperties.CLASSLOADER, Activator.class.getClassLoader());
			overrides.put(PersistenceUnitProperties.ECLIPSELINK_PERSISTENCE_XML, "C:\\eprofiler2\\SVN\\trunk\\eprofiler_plugins\\de.robotron.eprofiler.persistence.jpa\\bin\\META-INF\\persistence.xml");
			overrides.put(PersistenceUnitProperties.JDBC_URL,cons.getParameter("url"));
			overrides.put(PersistenceUnitProperties.JDBC_DRIVER, oracle.jdbc.OracleDriver.class.getName());
			overrides.put(PersistenceUnitProperties.JDBC_USER, cons.getParameter("user"));
			overrides.put(PersistenceUnitProperties.JDBC_PASSWORD, StorageManager.getDefault().getSecurityAdapter().decodePW(cons.getParameter("pass")));
//			EntityManagerFactory emf = Persistence.createEntityManagerFactory("de.robotron.eprofiler.persistence.jpa",overrides);
			EntityManagerFactory emf = provider.createEntityManagerFactory("de.robotron.eprofiler.persistence.jpa", overrides);
			emfactories.put(connectionName, emf);
			return emf;
		}
	}


I test it with and without the property PersistenceUnitProperties.ECLIPSELINK_PERSISTENCE_XML.

I test nearly everything that i found in the internet.
Re: (no subject) [message #699403 is a reply to message #696612] Thu, 21 July 2011 13:56 Go to previous messageGo to next message
MichaelS  is currently offline MichaelS Friend
Messages: 9
Registered: July 2011
Junior Member
any idea?
Re: EclipseLink + RCP + OSGI Service: No Persistence provider for EntityManager [message #699407 is a reply to message #684777] Thu, 21 July 2011 14:03 Go to previous messageGo to next message
MichaelS  is currently offline MichaelS Friend
Messages: 9
Registered: July 2011
Junior Member
has no one an idea?
Here I have more informations for us.

At the beginning the complete stacktrace:

javax.persistence.PersistenceException: No Persistence provider for EntityManager named de.robotron.eprofiler.persistence.jpa
	at javax.persistence.Persistence.createEntityManagerFactory(Unknown Source)
	at mainplugin.Activator.createEMF(Activator.java:88)
	at mainplugin.Activator.start(Activator.java:51)
	at org.eclipse.osgi.framework.internal.core.BundleContextImpl$1.run(BundleContextImpl.java:711)
	at java.security.AccessController.doPrivileged(Native Method)
	at org.eclipse.osgi.framework.internal.core.BundleContextImpl.startActivator(BundleContextImpl.java:702)
	at org.eclipse.osgi.framework.internal.core.BundleContextImpl.start(BundleContextImpl.java:683)
	at org.eclipse.osgi.framework.internal.core.BundleHost.startWorker(BundleHost.java:381)
	at org.eclipse.osgi.framework.internal.core.AbstractBundle.resume(AbstractBundle.java:389)
	at org.eclipse.osgi.framework.internal.core.Framework.resumeBundle(Framework.java:1130)
	at org.eclipse.osgi.framework.internal.core.StartLevelManager.resumeBundles(StartLevelManager.java:559)
	at org.eclipse.osgi.framework.internal.core.StartLevelManager.resumeBundles(StartLevelManager.java:544)
	at org.eclipse.osgi.framework.internal.core.StartLevelManager.incFWSL(StartLevelManager.java:457)
	at org.eclipse.osgi.framework.internal.core.StartLevelManager.doSetStartLevel(StartLevelManager.java:243)
	at org.eclipse.osgi.framework.internal.core.StartLevelManager.dispatchEvent(StartLevelManager.java:438)
	at org.eclipse.osgi.framework.internal.core.StartLevelManager.dispatchEvent(StartLevelManager.java:1)
	at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:230)
	at org.eclipse.osgi.framework.eventmgr.EventManager$EventThread.run(EventManager.java:340)


Here is the code that i use in the MainPlugin:

package mainplugin;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;

import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

import mainplugin.entities.TestEntity;
import mainplugin.interfac.IPersistenceAdapter;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.Platform;
import org.eclipse.persistence.config.PersistenceUnitProperties;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.BundleContext;

/**
 * The activator class controls the plug-in life cycle
 */
public class Activator extends AbstractUIPlugin {

	private EntityManagerFactory emf;
	private Connection connection;
	private static final String PERSISTENCE_UNIT = "de.robotron.eprofiler.persistence.jpa";
	private String connectionName = "ec4inst";
	private IPersistenceAdapter adapter =  null;
	// The plug-in ID
	public static final String PLUGIN_ID = "MainPlugin"; //$NON-NLS-1$

	// The shared instance
	private static Activator plugin;
	
	/**
	 * The constructor
	 */
	public Activator() {
	}

	/*
	 * (non-Javadoc)
	 * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
	 */
	public void start(BundleContext context) throws Exception {
//		super.start(context);
//		plugin = this;
		adapter = getPersistanceAdapter();
		createEMF();
		insertTree();
	}

	/*
	 * (non-Javadoc)
	 * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
	 */
	public void stop(BundleContext context) throws Exception {
		closeEMF();
		plugin = null;
		super.stop(context);
	}

	/**
	 * Returns the shared instance
	 *
	 * @return the shared instance
	 */
	public static Activator getDefault() {
		return plugin;
	}
public void createEMF() throws Exception {
		
		
		String url = "jdbc:oracle:thin:@RDSLINUX24:1521:ECr4inst";
		String user = "ec_sys";
		String password = "sys";
		String connectionName = "ec4inst";
		
		
		Map<String, String> overrides = new HashMap<String, String>();
		overrides.put(PersistenceUnitProperties.JDBC_URL, url);
		overrides.put(PersistenceUnitProperties.JDBC_DRIVER, oracle.jdbc.OracleDriver.class.getName());
		overrides.put(PersistenceUnitProperties.JDBC_USER, user);
		overrides.put(PersistenceUnitProperties.JDBC_PASSWORD, password);
		
		emf = Persistence.createEntityManagerFactory("de.robotron.eprofiler.persistence.jpa",overrides);
		adapter.getEmfactories().put(connectionName, emf);
		

		
		// wir erzwingen das Erzeugen der Tabellen
		emf.createEntityManager().close();
		// wir aktivieren das Logging
//		JpaHelper.getServerSession(emf).getSessionLog().setLevel(SessionLog.FINE);
	}

	public void closeEMF() {
		if (connection != null) {
			try {
				connection.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		if (emf != null) {
			emf.close();
		}
	}


	public void insertTree() {
	
		TestEntity entity = new TestEntity();
		entity.setName("sagasdgs");
		entity.setAttributes("asfsgg");
		adapter.saveEntity("ec4inst", entity);
	
	
	}

	public IPersistenceAdapter getPersistanceAdapter(){
		IPersistenceAdapter adapter = null;
		for(IConfigurationElement configurationElement : Platform.getExtensionRegistry().getConfigurationElementsFor("jpa_plugin.jpa.persistenceAdapter")){ 
			try {
				adapter = (IPersistenceAdapter)configurationElement.createExecutableExtension("class"); //$NON-NLS-1$
				return adapter;
			} catch (CoreException e) {
				e.printStackTrace();
				return null;
			}
		}
		return adapter;
	}
	
}


Thes are the dependencies of the jpa-plugin:

http://img19.imageshack.us/img19/650/dependencies.jpg

the following picture shows the structure of the Lib-Plugin:

http://img193.imageshack.us/img193/8543/libplugin.jpg

I have also add the plugins to th Target Platform:

http://img4.imageshack.us/img4/4584/javaxpersistence.jpg

http://img215.imageshack.us/img215/401/orgeclipsepersistence.jpg

My situtaion is the same. When i use the persisentence in the JPA-Plugin the persistence privider is found and i can save something.
When i star the same function from the Main-Plugin it doesn't work. It seems that the persistence.xml isn't loaded.
Should i put the persistence.xml into the Main_Plugin? But this doesn't work too.
Or can i load manual the persistence.xml.
I have no idea yet.
(no subject) [message #699412 is a reply to message #696612] Thu, 21 July 2011 13:56 Go to previous messageGo to next message
MichaelS  is currently offline MichaelS Friend
Messages: 9
Registered: July 2011
Junior Member
.

[Updated on: Mon, 25 July 2011 07:09]

Report message to a moderator

(no subject) [message #699414 is a reply to message #684777] Thu, 21 July 2011 14:03 Go to previous messageGo to next message
MichaelS  is currently offline MichaelS Friend
Messages: 9
Registered: July 2011
Junior Member
*edit*

[Updated on: Mon, 25 July 2011 07:09]

Report message to a moderator

Re: EclipseLink + RCP + OSGI Service: No Persistence provider for EntityManager [message #725398 is a reply to message #684777] Wed, 14 September 2011 16:41 Go to previous messageGo to next message
Marcus  is currently offline Marcus Friend
Messages: 2
Registered: September 2011
Junior Member
Hi Michael,

did you solve your problem?

I am pretty much in the situation described in your posts. Thus I would appreciate any guide to a solution.

Thanks!

Bye, Marcus
Re: EclipseLink + RCP + OSGI Service: No Persistence provider for EntityManager [message #729558 is a reply to message #725398] Mon, 26 September 2011 13:46 Go to previous messageGo to next message
Luiz E. is currently offline Luiz E.Friend
Messages: 97
Registered: September 2010
Member
just a heads up
the same thing happened to me here.
i just remove the 'provider' tag from my persistence.xml
here is my entitymanagetfactory

package br.com.germantech.ecf.infraestrutura.persistencia.entityManager;

import java.util.HashMap;
import java.util.Map;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;

import org.eclipse.persistence.config.PersistenceUnitProperties;
import org.eclipse.persistence.config.TargetDatabase;
import org.eclipse.persistence.jpa.osgi.PersistenceProvider;
import org.postgresql.Driver;

import br.com.germantech.ecf.Bootstrap;

public abstract class ECFEntityManager {

	private static EntityManagerFactory emf = null;
	private static Map<String, Object> properties = new HashMap<String, Object>();

	private static final ThreadLocal<EntityManager> ENTITY_MANAGER_CACHE = new ThreadLocal<EntityManager>();

	private static void init() {
		properties.put(PersistenceUnitProperties.TARGET_DATABASE, TargetDatabase.PostgreSQL);
		properties.put(PersistenceUnitProperties.JDBC_DRIVER, Driver.class.getCanonicalName());
		properties.put(PersistenceUnitProperties.JDBC_URL,"jdbc:postgresql://*******/ecf");
		properties.put(PersistenceUnitProperties.JDBC_USER, "postgres");
		properties.put(PersistenceUnitProperties.JDBC_PASSWORD, "*********");
		properties.put(PersistenceUnitProperties.CONNECTION_POOL_MIN, "5");
		properties.put(PersistenceUnitProperties.CONNECTION_POOL_MAX, "10");
		properties.put(PersistenceUnitProperties.CACHE_SHARED_DEFAULT,"false");
		properties.put(PersistenceUnitProperties.CACHE_STATEMENTS,"false");
		properties.put(PersistenceUnitProperties.BATCH_WRITING, "JDBC");
		properties.put(PersistenceUnitProperties.CLASSLOADER, Bootstrap.class.getClassLoader());
		
		// Cria tabelas novas (mas não atualiza)
//		properties.put(PersistenceUnitProperties.DDL_GENERATION, "create-tables");
		
		properties.put("eclipselink.logging.level", "FINE");
		properties.put("eclipselink.logging.timestamp", "false");
		properties.put("eclipselink.logging.session", "false");
		properties.put("eclipselink.logging.thread", "false");
		properties.put("eclipselink.logging.exceptions", "true");

		emf = new PersistenceProvider().createEntityManagerFactory("ecf", properties);
	}

	public static EntityManager createEntityManager() {
		EntityManager entityManager = ENTITY_MANAGER_CACHE.get();
		if (entityManager == null) {
			init();
			ENTITY_MANAGER_CACHE.set(emf.createEntityManager());
		}
		return entityManager;
	}

}


Re: EclipseLink + RCP + OSGI Service: No Persistence provider for EntityManager [message #729566 is a reply to message #725398] Mon, 26 September 2011 13:46 Go to previous messageGo to next message
Luiz E. is currently offline Luiz E.Friend
Messages: 97
Registered: September 2010
Member
just a heads up
the same thing happened to me here.
i just remove the 'provider' tag from my persistence.xml
here is my entitymanagetfactory


package br.com.germantech.ecf.infraestrutura.persistencia.entityManager;

import java.util.HashMap;
import java.util.Map;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;

import org.eclipse.persistence.config.PersistenceUnitProperties;
import org.eclipse.persistence.config.TargetDatabase;
import org.eclipse.persistence.jpa.osgi.PersistenceProvider;
import org.postgresql.Driver;

import br.com.germantech.ecf.Bootstrap;

public abstract class ECFEntityManager {

private static EntityManagerFactory emf = null;
private static Map<String, Object> properties = new HashMap<String, Object>();

private static final ThreadLocal<EntityManager> ENTITY_MANAGER_CACHE = new ThreadLocal<EntityManager>();

private static void init() {
properties.put(PersistenceUnitProperties.TARGET_DATABASE, TargetDatabase.PostgreSQL);
properties.put(PersistenceUnitProperties.JDBC_DRIVER, Driver.class.getCanonicalName());
properties.put(PersistenceUnitProperties.JDBC_URL,"jdbc:postgresql://*******/ecf");
properties.put(PersistenceUnitProperties.JDBC_USER, "postgres");
properties.put(PersistenceUnitProperties.JDBC_PASSWORD, "*********");
properties.put(PersistenceUnitProperties.CONNECTION_POOL_MIN, "5");
properties.put(PersistenceUnitProperties.CONNECTION_POOL_MAX, "10");
properties.put(PersistenceUnitProperties.CACHE_SHARED_DEFAULT,"false");
properties.put(PersistenceUnitProperties.CACHE_STATEMENTS,"false");
properties.put(PersistenceUnitProperties.BATCH_WRITING, "JDBC");
properties.put(PersistenceUnitProperties.CLASSLOADER, Bootstrap.class.getClassLoader());

// Cria tabelas novas (mas não atualiza)
// properties.put(PersistenceUnitProperties.DDL_GENERATION, "create-tables");

properties.put("eclipselink.logging.level", "FINE");
properties.put("eclipselink.logging.timestamp", "false");
properties.put("eclipselink.logging.session", "false");
properties.put("eclipselink.logging.thread", "false");
properties.put("eclipselink.logging.exceptions", "true");

emf = new PersistenceProvider().createEntityManagerFactory("ecf", properties);
}

public static EntityManager createEntityManager() {
EntityManager entityManager = ENTITY_MANAGER_CACHE.get();
if (entityManager == null) {
init();
ENTITY_MANAGER_CACHE.set(emf.createEntityManager());
}
return entityManager;
}

}
Re: EclipseLink + RCP + OSGI Service: No Persistence provider for EntityManager [message #729691 is a reply to message #729558] Mon, 26 September 2011 19:03 Go to previous message
Marcus  is currently offline Marcus Friend
Messages: 2
Registered: September 2011
Junior Member
Thanks for the code!

I had to do the same, i.e. remove the "provider" tag, although it contained the right class. BTW: I've been able to put the remaining properties into the .xml file, hard-coding it was not necessary.

Bye and thanks for the confirmation,

Marcus
Re: EclipseLink + RCP + OSGI Service: No Persistence provider for EntityManager [message #729694 is a reply to message #729558] Mon, 26 September 2011 19:03 Go to previous message
Marcus is currently offline MarcusFriend
Messages: 7
Registered: July 2009
Junior Member
Thanks for the code!

I had to do the same, i.e. remove the "provider" tag, although it contained the right class. BTW: I've been able to put the remaining properties into the .xml file, hard-coding it was not necessary.

Bye and thanks for the confirmation,

Marcus
Previous Topic:StackOverFlowError on Eclipselink commit
Next Topic:Re: sync error with eclipselink
Goto Forum:
  


Current Time: Sat Dec 20 16:04:03 GMT 2014

Powered by FUDForum. Page generated in 0.02022 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software