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.xml
	<persistence-unit name="myPU" transaction-type="JTA">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
		
		<jta-data-source>
			<![CDATA[
			osgi:javax.sql.DataSource/(name=ManagedDemoDs)
			]]>
		</jta-data-source>
		
		<non-jta-data-source>
			<![CDATA[
			osgi:javax.sql.DataSource/(name=DemoDs)
			]]>
		</non-jta-data-source>
		
    	<class>persistence.service.simple.SimplePersonService</class>
		
		<properties>
			<property name="javax.persistence.jdbc.driver" value="org.postgresql.Driver" />
			<property name="javax.persistence.jdbc.url" value="jdbc:postgres://10.50.10.15:5432/test" />
			<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="hibernate.hbm2ddl.auto" 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 -->
		</properties>
	</persistence-unit>


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

import java.util.Properties;

import javax.persistence.EntityManagerFactory;

import org.apache.felix.dm.Component;
import org.apache.felix.dm.DependencyActivatorBase;
import org.apache.felix.dm.DependencyManager;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;

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

	@Override
	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)
	                    .setImplementation(SimplePersonService.class)
	                    .add(createServiceDependency()
	                            .setService(
	                                EntityManagerFactory.class, "(osgi.unit.name=myPU)")
	                            .setRequired(true));
	    
		manager.add(comp);
		
	}
}


The SimplePersonService.java
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 org.apache.felix.dm.annotation.api.Component;
import org.apache.felix.dm.annotation.api.Property;
import org.apache.felix.dm.annotation.api.ServiceDependency;

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

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

	@Override
	public void addPerson(Person person) {
		// update
		System.out.println("em="+em);;
		System.out.println("Created "+person.getName());
		
		listPersons().add(person);
	}

	public void start()
	{
		addPerson(new Person("Devoxx", "Antwerp", "me@test1.com", "555-555-5555"));
		addPerson(new Person("Jfokus", "Stockholm", "me@test2.com", "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 10.50.10.15 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.

Quote:

____________________________
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
em=null
Created Devoxx Antwerp
em=null
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: Thu Sep 19 13:25:19 GMT 2024

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

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

Back to the top