Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Gemini » Gemini injection not working(Having issue with injecting EntityManager for Postgres database)
Gemini injection not working [message #1780289] Fri, 19 January 2018 15:49
Jim Rayburn is currently offline Jim RayburnFriend
Messages: 1
Registered: January 2018
Junior Member
My development environment is using Eclipse Oxygen with BndTools. I am using the Apache Felix osgi framework with Gemini JPA. Attempting to access a Postgres database that is on another server. I defined the persistence.xml file with the necessary properties to define the location of the database.

It appears that the provider is being loaded from the log output to the console. It does not appear to be injecting the EntityManager with the correct provider though.

I attempted a similar test on Amdatu with less success as it doesn't even try to load the provider from the persistence.xml file and will not call the service start method.

	<persistence-unit name="myPU" transaction-type="JTA">
			<property name="javax.persistence.jdbc.driver" value="org.postgresql.Driver" />
			<property name="javax.persistence.jdbc.url" value="jdbc:postgres://" />
			<property name="javax.persistence.jdbc.user" value="user" />
			<property name="javax.persistence.jdbc.password" value="pwd" />
			<property name="eclipselink.logging.level" value="ALL" />

			<!-- EclipseLink specific properties -->
			<property name="eclipselink.ddl-generation" value="createtables" />
			<property name="eclipselink.ddl-generation.output-mode" value="database" />

    		<property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect"/> <!-- DB Dialect -->
            <property name="" value="update" /> <!-- create / create-drop / update -->
            <property name="hibernate.show_sql" value="true" /> <!-- Show SQL in console -->
            <property name="hibernate.format_sql" value="true" /> <!-- Show SQL formatted -->

The Activator class is defined as follows.
package persistence.service.simple;

import java.util.Properties;

import javax.persistence.EntityManagerFactory;

import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;

 * @author afatdsprod\rayburnj
public class Activator 
	extends DependencyActivatorBase
	implements BundleActivator

	public void init(BundleContext context, DependencyManager manager) throws Exception 
	    Properties props = new Properties();
	    props.put("transactional", SimplePersonService.class.getName());

	    Component comp = createComponent()
	                    .setInterface(Object.class.getName(), props)
	                                EntityManagerFactory.class, "(")

package persistence.service.simple;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import javax.persistence.PersistenceContext;
import javax.transaction.Transactional;


import persistence.api.Person;
import persistence.api.Team;

    properties=@Property(name="persistent", value="true"))
public class SimplePersonService 
	implements Team
	private List<Person> listPersons = new ArrayList<>();
	private volatile EntityManager em;
	public SimplePersonService()
	public List<Person> listPersons() {
		//List<Person> persons = em.fin
		// TODO Auto-generated method stub
		return listPersons;

	public void addPerson(Person person) {
		// update
		System.out.println("Created "+person.getName());

	public void start()
		addPerson(new Person("Devoxx", "Antwerp", "", "555-555-5555"));
		addPerson(new Person("Jfokus", "Stockholm", "", "555-555-6666"));
		System.out.println("Total of " + listPersons().size() + " persons");

I have tested that the database port is accessible from my development box using
% telnet 5432

It connects to the port.

When I run the osgi bundle, the provider appears to attempt to be loaded (see output below). The EntityManager injection appears to not have occurred. I see this as the EntityManager is still null. This is determined by em=null. In my test case below I have not performed any function calls from the em object.


Welcome to Apache Felix Gogo

g! [EL Finest]: jpa: 2018-01-19 10:35:20.486--ServerSession(1922147812)--Thread(Thread[FelixFrameworkWiring,5,main])--Begin predeploying Persistence Unit myPU; session myPU; state Initial; factoryCount 0
[EL Finest]: properties: 2018-01-19 10:35:20.497--ServerSession(1922147812)--Thread(Thread[FelixFrameworkWiring,5,main])--property=eclipselink.orm.throw.exceptions; default value=true
[EL Finest]: properties: 2018-01-19 10:35:20.497--ServerSession(1922147812)--Thread(Thread[FelixFrameworkWiring,5,main])--property=eclipselink.weaving.changetracking; default value=true
[EL Finest]: properties: 2018-01-19 10:35:20.497--ServerSession(1922147812)--Thread(Thread[FelixFrameworkWiring,5,main])--property=eclipselink.weaving.lazy; default value=true
[EL Finest]: properties: 2018-01-19 10:35:20.497--ServerSession(1922147812)--Thread(Thread[FelixFrameworkWiring,5,main])--property=eclipselink.weaving.eager; default value=false
[EL Finest]: properties: 2018-01-19 10:35:20.497--ServerSession(1922147812)--Thread(Thread[FelixFrameworkWiring,5,main])--property=eclipselink.weaving.fetchgroups; default value=true
[EL Finest]: properties: 2018-01-19 10:35:20.497--ServerSession(1922147812)--Thread(Thread[FelixFrameworkWiring,5,main])--property=eclipselink.weaving.internal; default value=true
[EL Finest]: properties: 2018-01-19 10:35:20.498--ServerSession(1922147812)--Thread(Thread[FelixFrameworkWiring,5,main])--property=eclipselink.multitenant.tenants-share-emf; default value=true
[EL Finest]: properties: 2018-01-19 10:35:20.498--ServerSession(1922147812)--Thread(Thread[FelixFrameworkWiring,5,main])--property=eclipselink.multitenant.tenants-share-cache; default value=false
[EL Finer]: metadata: 2018-01-19 10:35:20.507--ServerSession(1922147812)--Thread(Thread[FelixFrameworkWiring,5,main])--Searching for default mapping file in bundle://16.0:0/ (There is no English translation for this message.)
[EL Finer]: metadata: 2018-01-19 10:35:20.508--ServerSession(1922147812)--Thread(Thread[FelixFrameworkWiring,5,main])--Searching for default mapping file in bundle://16.0:0/ (There is no English translation for this message.)
[EL Finest]: jpa: 2018-01-19 10:35:20.521--ServerSession(1922147812)--Thread(Thread[FelixFrameworkWiring,5,main])--End predeploying Persistence Unit myPU; session myPU; state Predeployed; factoryCount 0
Created Devoxx Antwerp
Created Jfokus Stockholm
Total of 2 persons
Previous Topic:Gemini JPA and Java 9
Next Topic:Gemini Naming java:comp URL Context
Goto Forum:

Current Time: Mon Dec 11 21:11:02 GMT 2023

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

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

Back to the top