Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Gemini » Moving from persistence.xml to ConfigurationAdmin
Moving from persistence.xml to ConfigurationAdmin [message #1016269] Tue, 05 March 2013 18:25 Go to next message
Luiz E. is currently offline Luiz E.Friend
Messages: 100
Registered: September 2010
Senior Member
I was dealing with this problem:
and probably came to a solution. As I described on the other topic, I need to create plug-ins to some clients, and these plug-ins will create new tables on our base. I just created a fragment with these new models, and need to make the 'core' plugin scan this fragment too, and add those classes to the current persitent unit...
I came across Standalone Configuration ( but I need to know how to make this works with our current now, we have a persitence.xml file, and a EntityManagerHelper class that creates the EMF and the EM too, like this


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

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

import org.apache.log4j.Logger;
import org.eclipse.persistence.config.PersistenceUnitProperties;
import org.eclipse.persistence.config.TargetDatabase;
import org.eclipse.persistence.internal.jpa.EntityManagerImpl;
import org.eclipse.persistence.jpa.PersistenceProvider;
import org.eclipse.persistence.sessions.UnitOfWork;
import org.postgresql.Driver;


public abstract class GermantechEntityManager {

	private static Logger log = Logger.getLogger(GermantechEntityManager.class);
	private static EntityManagerFactory emf = null;
	private static Map<String, Object> properties = new HashMap<String, Object>();

	private static UnitOfWork uow;

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

	private synchronized static void init() {
		properties.put(PersistenceUnitProperties.TARGET_DATABASE, TargetDatabase.PostgreSQL);
		properties.put(PersistenceUnitProperties.JDBC_DRIVER, Driver.class.getCanonicalName());
		properties.put(PersistenceUnitProperties.JDBC_URL, PropertiesHelper.getProperty(PropertiesHelper.URL));
		properties.put(PersistenceUnitProperties.JDBC_USER, PropertiesHelper.getProperty(PropertiesHelper.USUARIO));
		properties.put(PersistenceUnitProperties.JDBC_PASSWORD, PropertiesHelper.getProperty(PropertiesHelper.SENHA));
		properties.put(PersistenceUnitProperties.CONNECTION_POOL_MIN, "1");
		properties.put(PersistenceUnitProperties.CONNECTION_POOL_MAX, "10");
		properties.put(PersistenceUnitProperties.CACHE_STATEMENTS, "true");
		properties.put(PersistenceUnitProperties.BATCH_WRITING, "JDBC");
		properties.put(PersistenceUnitProperties.CLASSLOADER, Bootstrap.class.getClassLoader());
		// Cria tabelas novas (mas não atualiza)
		if("true".equalsIgnoreCase(PropertiesHelper.getProperty(PropertiesHelper.GERAR_TABELAS))){"Gerando tabelas...");
			properties.put(PersistenceUnitProperties.DDL_GENERATION, PersistenceUnitProperties.CREATE_OR_EXTEND);
		// Cria os arquivos de geração do banco de dados
//		properties.put(PersistenceUnitProperties.CREATE_JDBC_DDL_FILE, "createDDL_ddlGeneration.jdbc");
//		properties.put(PersistenceUnitProperties.DDL_GENERATION_MODE, PersistenceUnitProperties.DDL_BOTH_GENERATION);
		properties.put("eclipselink.logging.level", "FINE");
		properties.put("eclipselink.logging.timestamp", "true");
		properties.put("eclipselink.logging.session", "true");
		properties.put("eclipselink.logging.thread", "true");
		properties.put("eclipselink.logging.exceptions", "true");
		emf = new PersistenceProvider().createEntityManagerFactory("gtech", properties);

	 * Retorna um {@link EntityManager}. Caso não exista, cria um novo
	public synchronized static EntityManager getEntityManager() {
		EntityManager entityManager = ENTITY_MANAGER_CACHE.get();
		if (entityManager == null) {"entityManager é null");
			ENTITY_MANAGER_CACHE.set(entityManager = emf.createEntityManager());
		return entityManager;

any idea is much appreciated

[Updated on: Tue, 05 March 2013 18:29]

Report message to a moderator

Re: Moving from persistence.xml to ConfigurationAdmin [message #1019028 is a reply to message #1016269] Thu, 14 March 2013 22:55 Go to previous message
Michael Keith is currently offline Michael KeithFriend
Messages: 240
Registered: July 2009
Senior Member
Luiz, after what you learned from the other thread did you still need the config admin feature?
Previous Topic:Installing features in integration tests.
Next Topic:[Gemini-naming] Referecing an Osgi service with filter fails
Goto Forum:

Current Time: Mon Feb 20 04:24:52 GMT 2017

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

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