Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » exclude-unlisted-classes=false in Equinox OSGI
exclude-unlisted-classes=false in Equinox OSGI [message #554770] Tue, 24 August 2010 11:39 Go to next message
Filipp A. is currently offline Filipp A.Friend
Messages: 49
Registered: February 2010
Member
Hi All!
I trying to get exclude-unlisted-classes to work in equinox, but no luck.....

please have a look to my simple osgi-plugins: test.eclipselink and test.eclipselink.data (code see below)

did i something forget?
any Ideas?

Thanks in advance!!

My Environment is:
Eclipselink 2.1
Eclipse Helios
Java: Java(TM) SE Runtime Environment (build 1.6.0_20-b02)
Java HotSpot(TM) Server VM (build 16.3-b01, mixed mode)


Plugin test.eclipselink
|-src
| |-test.eclipselink
| |-AbstractDaoActivator.java
| |-Activator.java
|-META-INF
| |-MANIFEST.MF

AbstractDaoActivator.java
package test.eclipselink;

import java.util.HashMap;
import java.util.Map;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.spi.PersistenceUnitTransactionType;
import org.eclipse.persistence.config.PersistenceUnitProperties;
import org.eclipse.persistence.jpa.osgi.PersistenceProvider;
import org.osgi.framework.BundleActivator;

abstract public class AbstractDaoActivator implements BundleActivator {
	
	private static AbstractDaoActivator plugin;

	private static EntityManagerFactory entityManagerFactory;
	private static EntityManager entityManager;
	private ClassLoader modelClassLoader;
	private String persistenceUnitName;
	
	public AbstractDaoActivator(ClassLoader modelClassLoader, String persistenceUnitName){
		plugin = this;
		this.modelClassLoader = modelClassLoader;
		this.persistenceUnitName = persistenceUnitName;
	}
	
	public static AbstractDaoActivator getDefault(){
		return plugin;
	}
	
    protected void connect(){
    		initEntityManager();
    }
    
    public EntityManager getEntityManager(){
    	return entityManager;
    }
    
    protected void disconnect(){
		if (entityManagerFactory != null){
			entityManagerFactory.close();
		}
    }
	
	private void initEntityManager() {
		if (entityManager == null) {
		 	entityManagerFactory = new PersistenceProvider().createEntityManagerFactory(persistenceUnitName, getEntityManagerProperties());
			entityManager = entityManagerFactory.createEntityManager();
		}
	}
    
    
	protected Map<String, Object> getEntityManagerProperties(){
		Map<String, Object> properties = new HashMap<String, Object>();
		properties.put("javax.persistence.transactionType", PersistenceUnitTransactionType.RESOURCE_LOCAL.name());
//		properties.put("eclipselink.target-database", TargetDatabase.MySQL);
		properties.put("javax.persistence.jdbc.driver", "org.gjt.mm.mysql.Driver");
		properties.put("javax.persistence.jdbc.url", "jdbc:mysql://127.0.0.1/test");
		properties.put("javax.persistence.jdbc.user", "test");
		properties.put("javax.persistence.jdbc.password", "test");
//		properties.put("eclipselink.ddl-generation", "drop-and-create-tables");
		properties.put("eclipselink.ddl-generation", "create-tables");
		properties.put("eclipselink.ddl-generation.output-mode", "database");
		properties.put("eclipselink.jdbc.read-connections.min", "1");
		properties.put("eclipselink.jdbc.write-connections.min", "1");
	//	properties.put("eclipselink.cache.shared.default", "true");
	//	properties.put("eclipselink.jdbc.batch-writing", "JDBC");
	
		// ClassLoader
		properties.put(PersistenceUnitProperties.CLASSLOADER, this.modelClassLoader);
		
		// Logging
		properties.put("eclipselink.logging.level", "FINE"); // OFF
		properties.put("eclipselink.logging.timestamp", "false");
		properties.put("eclipselink.logging.session", "false");
		properties.put("eclipselink.logging.thread", "false");
			
		properties.put("eclipselink.weaving", "true");

		return properties;
	}
}


Activator.java
package test.eclipselink;

import org.osgi.framework.BundleContext;
import test.eclipselink.data.Data1;

public class Activator extends AbstractDaoActivator {

	public Activator() {
		super(Data1.class.getClassLoader(), "test.eclipselink.data");
	}

	private static BundleContext context;

	static BundleContext getContext() {
		return context;
	}

	public void start(BundleContext bundleContext) throws Exception {
		Activator.context = bundleContext;
		connect();
	}

	public void stop(BundleContext bundleContext) throws Exception {
		Activator.context = null;
	}
}


MANIFEST.MF
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Eclipselink
Bundle-SymbolicName: test.eclipselink
Bundle-Version: 1.0.0.qualifier
Bundle-Activator: test.eclipselink.Activator
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Import-Package: org.osgi.framework;version="1.3.0"
Require-Bundle: javax.persistence;bundle-version="2.0.1",
 org.eclipse.persistence.jpa;bundle-version="2.1.0",
 test.eclipselink.data;bundle-version="1.0.0"
Bundle-ClassPath: .


Plugin test.eclipselink.data
|-src
| |-test.eclipselink.data
| |-Data1.java
| |-Data2.java
| |-META-INF
| | |-MANIFEST.MF (empty)
| | |-persistence.xml
|-META-INF
| |-MANIFEST.MF

Data1.java
package test.eclipselink.data;

import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;

@Entity
@Table(name="Data1")
public class Data1 {

	@Id
	private long id;
	public long getId() { return id; }
	public void setId(long id) { this.id = id; }
}



Data2.java
package test.eclipselink.data;

import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;

@Entity
@Table(name="Data2")
public class Data2 {

	@Id
	private long id;
	public long getId() { return id; }
	public void setId(long id) { this.id = id; }
}


src/META-INF/MANIFEST.MF
Manifest-Version: 1.0
Class-Path: 


src/META-INF/persistence.xml
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
	<persistence-unit name="test.eclipselink.data">
		<class>test.eclipselink.data.Data1</class>
		<exclude-unlisted-classes>false</exclude-unlisted-classes>
	</persistence-unit>
</persistence>


MANIFEST.MF
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Data
Bundle-SymbolicName: test.eclipselink.data
Bundle-Version: 1.0.0.qualifier
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Require-Bundle: javax.persistence;bundle-version="2.0.1"
Export-Package: test.eclipselink.data
Bundle-ClassPath: mysql-connector-java-5.1.10-bin.jar,
 .
JPA-PersistenceUnits: test.eclipselink.data


OSGI Bundles
javax.persistence  : Start Level 1
org.eclipse.persistence.jpa : Start Level 2

Framework : Equinox
Default Start Level : 6
Default Auto-Start : true


OSGI Run Configuration VM arguments
-Dosgi.requiredJavaVersion=1.5 -XX:MaxPermSize=256m -Xms40m -Xmx512m -Declipse.ignoreApp=true -Dosgi.noShutdown=true -Dosgi.framework.extensions=org.eclipse.persistence.jpa.equinox.weaving


Console: (only Data1 is mapped.... )
osgi> [EL Config]: The access type for the persistent class [class test.eclipselink.data.Data1] is set to [FIELD].
[EL Config]: The alias name for the entity class [class test.eclipselink.data.Data1] is being defaulted to: Data1.
[EL Config]: The column name for element [field id] is being defaulted to: ID.
[EL Info]: EclipseLink, version: Eclipse Persistence Services - 2.1.0.v20100614-r7608
[EL Fine]: Detected Vendor platform: org.eclipse.persistence.platform.database.MySQLPlatform
[EL Config]: Connection(27890503)--connecting(DatabaseLogin(
	platform=>MySQLPlatform
	user name=> "test"
	datasource URL=> "jdbc:mysql://127.0.0.1/test"
))
[EL Config]: Connection(20348456)--Connected: jdbc:mysql://127.0.0.1/test
	User: test@localhost
	Database: MySQL  Version: 5.1.41-3ubuntu12.6
	Driver: MySQL-AB JDBC Driver  Version: mysql-connector-java-5.1.10 ( Revision: ${svn.Revision} )
[EL Config]: Connection(9744175)--connecting(DatabaseLogin(
	platform=>MySQLPlatform
	user name=> "test"
	datasource URL=> "jdbc:mysql://127.0.0.1/test"
))
[EL Config]: Connection(11001145)--Connected: jdbc:mysql://127.0.0.1/test
	User: test@localhost
	Database: MySQL  Version: 5.1.41-3ubuntu12.6
	Driver: MySQL-AB JDBC Driver  Version: mysql-connector-java-5.1.10 ( Revision: ${svn.Revision} )
[EL Info]: test.eclipselink.data_transactionType=RESOURCE_LOCAL_url=jdbc:mysql://127.0.0.1/test_user=test login successful
[EL Fine]: Connection(20348456)--CREATE TABLE Data1 (ID BIGINT NOT NULL, PRIMARY KEY (ID))


ss
ss

Framework is launched.

id	State       Bundle
0	ACTIVE      org.eclipse.osgi_3.6.0.v20100517
	            Fragments=3, 16
1	ACTIVE      org.eclipse.persistence.jpa_2.1.0.v20100614-r7608
	            Fragments=10, 13
2	ACTIVE      javax.mail.glassfish_1.4.1.v201005082020
3	RESOLVED    javax.transaction_1.1.1.v201006150915
	            Master=0
5	ACTIVE      org.apache.ant_1.7.1.v20100518-1145
7	ACTIVE      javax.resource_1.5.0.v200906010428
8	ACTIVE      javax.xml.stream_1.0.1.v201004272200
9	ACTIVE      org.eclipse.persistence.core_2.1.0.v20100614-r7608
	            Fragments=15
10	RESOLVED    org.eclipse.persistence.jpa.osgi_2.1.0.v20100614-r7608
	            Master=1
11	ACTIVE      javax.xml_1.3.4.v201005080400
12	ACTIVE      javax.persistence_2.0.1.v201006031150
13	RESOLVED    org.eclipse.persistence.jpa.equinox_2.1.0.v20100614-r7608
	            Master=1
14	ACTIVE      org.eclipse.persistence.asm_2.1.0.v20100614-r7608
15	RESOLVED    org.eclipse.persistence.oracle_2.1.0.v20100614-r7608
	            Master=9
16	RESOLVED    org.eclipse.persistence.jpa.equinox.weaving_2.1.0.v20100614-r7608
	            Master=0
17	ACTIVE      javax.activation_1.1.0.v201005080500
18	ACTIVE      javax.jms_1.1.0.v200906010428
19	ACTIVE      org.eclipse.persistence.antlr_2.1.0.v20100614-r7608
21	ACTIVE      test.eclipselink_1.0.0.qualifier
22	ACTIVE      test.eclipselink.data_1.0.0.qualifier

osgi> 

Re: exclude-unlisted-classes=false in Equinox OSGI [message #555180 is a reply to message #554770] Wed, 25 August 2010 17:59 Go to previous messageGo to next message
Shaun Smith is currently offline Shaun SmithFriend
Messages: 197
Registered: July 2009
Senior Member
Use of exclude-unlisted-classes=false in Java SE is unusual because it is so expensive and I don't think I've ever tried it in OSGi. Given the restrictions in OSGi it's possible that it may prove problematic. I'll take a look.

That being said, why not just list the two classes? Smile

BTW, development of OSGi Enterprise Spec compliant support for JPA with EclipseLink is taking place in the Gemini JPA project. You might want to check it out.

--Shaun
Re: exclude-unlisted-classes=false in Equinox OSGI [message #555198 is a reply to message #555180] Wed, 25 August 2010 19:18 Go to previous messageGo to next message
Filipp A. is currently offline Filipp A.Friend
Messages: 49
Registered: February 2010
Member
thank you for your reply!
about SE you can be right, but it must be some solution for this....
Quote:
That being said, why not just list the two classes?

Idea is - i have one main plug-in with main abstract classes and other fragments/plugin used this main plug-in entities in same persistent unit.
with classes declaration it is not possible... or ?!
the best solution was, in my opinion, to have some possibility to create persistence.xml on the fly, or read mapped classes from the extensions points....
Quote:
... Gemini JPA ...

thanks, I'll be reading about it!
Re: exclude-unlisted-classes=false in Equinox OSGI [message #555201 is a reply to message #555198] Wed, 25 August 2010 19:29 Go to previous messageGo to next message
Shaun Smith is currently offline Shaun SmithFriend
Messages: 197
Registered: July 2009
Senior Member
The idea of persistence unit fragments is something that has been raised before and is something the JPA expert group will probably look at for JPA 2.0+. In the meantime I see how you thought of using auto detection as the way to achieve this to some degree.

But in your example you have the two entity classes in the same bundle. In this case I can imagine detection working (though it didn't). With entities in a collection of bundles I seriously doubt it would work in OSGi without some further infrastructure in EclipseLink.

FYI, in the _current_ OSGi Enterprise Spec all JPA entities and all JPA metadata files must reside in a single "persistence bundle"--which kind of torpedoes the possibility of assembling your persistence unit from a set of bundles.

--Shaun
Re: exclude-unlisted-classes=false in Equinox OSGI [message #555205 is a reply to message #555201] Wed, 25 August 2010 19:40 Go to previous messageGo to next message
Filipp A. is currently offline Filipp A.Friend
Messages: 49
Registered: February 2010
Member
ok, i understand....
Quote:
all JPA entities and all JPA metadata files must reside in a single "persistence bundle"

it's ok, i can use it with fragments and exclude-unlisted-classes=false .... but it's not work.... for me....
for eclipselink 1.x was some hack solution for custom persistence.xml at runtime ( http://java.randgestalten.de/index.php/2009/02/set-jpa-entit ies-at-runtime/)....I'll will be happy with it too... and, i can make it for me for 2.1, but i don't have fun to make it for every new release.... Sad and yet i try all possibilities to get it works without hack of the original code....
Re: exclude-unlisted-classes=false in Equinox OSGI [message #555413 is a reply to message #555205] Thu, 26 August 2010 14:22 Go to previous messageGo to next message
Shaun Smith is currently offline Shaun SmithFriend
Messages: 197
Registered: July 2009
Senior Member
Looks like a bug. I've filed: https://bugs.eclipse.org/323711. Please vote for this bug.

--Shaun

[Updated on: Thu, 26 August 2010 14:22]

Report message to a moderator

Re: exclude-unlisted-classes=false in Equinox OSGI [message #555429 is a reply to message #555413] Thu, 26 August 2010 14:47 Go to previous messageGo to next message
Filipp A. is currently offline Filipp A.Friend
Messages: 49
Registered: February 2010
Member
done! thanks!
Re: exclude-unlisted-classes=false in Equinox OSGI [message #656561 is a reply to message #554770] Sat, 26 February 2011 20:27 Go to previous messageGo to next message
Clemens is currently offline ClemensFriend
Messages: 2
Registered: February 2011
Junior Member
Hi there,

I still can't get entity auto discovery work with equinox and eclipselink 2.2.0.v20110202-r8913 - can anybody help?
The bug that was filed under https://bugs.eclipse.org/323711 has been marked as being a duplicate of https://bugs.eclipse.org/bugs/show_bug.cgi?id=329381 and this one has been marked as being fixed.
Looking at the sources, org.eclipse.persistence.internal.jpa.deployment.ArchiveFacto ryImpl still only checks for protocols 'file' and 'jar' but omits 'bundleresource' and thus is creating an URLArchive which returns an empty list when calling #getEntries().
So is entity auto-discovery simply unsupported in equinox/osgi?

Thanks in advance,

Clemens
Re: exclude-unlisted-classes=false in Equinox OSGI [message #656813 is a reply to message #656561] Mon, 28 February 2011 17:22 Go to previous messageGo to next message
Shaun Smith is currently offline Shaun SmithFriend
Messages: 197
Registered: July 2009
Senior Member
Hi Clemens,

In Tom's first comment on bug 329381 he says the fix provides "Support for discovery of classes in persistence unit when using Gemini OSGi" JPA.

Our current approach is to add JPA OSGi features to Gemini JPA as the current EclipseLink OSGi support is not OSGi Enterprise Specification compliant and is officially deprecated in 2.3. The fixes Tom put into EclipseLink were necessary to enable this feature in Gemini, which I've confirmed does work. I'd encourage you to move to Gemini JPA for JPA in OSGi.

--Shaun
Re: exclude-unlisted-classes=false in Equinox OSGI [message #890145 is a reply to message #656813] Thu, 21 June 2012 09:30 Go to previous message
Thomas Gillet is currently offline Thomas GilletFriend
Messages: 14
Registered: May 2011
Junior Member
Hi all,

I'm awaking an old post, hope someone is still listening...

I'm trying to use the entity auto-discovery feature in Gemini JPA.
Shaun confirmed in the previous message that it does work, but I don't see how.

I use Virgo 3.0.1 / Gemini JPA 1.0.0 / Gemini DBAccess 1.0.0 / EclipseLink 2.3.0 (all release versions).
I have a bundle with an annotated entity and <exclude-unlisted-classes>false</exclude-unlisted-classes> in my persistence.xml.

But still no entity in my PU.
Did I forgot something?

Thanks,
Thomas
Previous Topic:Logging sql with logback
Next Topic:Problem with select case from Criteria API
Goto Forum:
  


Current Time: Thu Mar 28 09:03:07 GMT 2024

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

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

Back to the top