EntityManager life cycle in OSGi application [message #385459] |
Wed, 11 February 2009 17:22 |
Eclipse User |
|
|
|
Originally posted by: laurent.legoff.geensys.com
Hi all,
we've just chosen to use eclipse link in our project. looks to be a
great solution to access database.
I'm new to Object-Relational Mapping solution. We would like to know how
to integrate eclipselink in our project that uses equinox:
- we make out first code in the application, I would like to know how
to manage EntityManager lifecycle:
Do we have to create an EntityManager each time we want to access
database (access+modification)?
Do we have to create an EntityManager for each Bundles that would like
to access database?
what is the best approach for an equinox server that run multiple
applications for one database ?
best regards,
Laurent.
ps:trace of my first test:
I hoped that initialization is faster
First time I access the database
0 - Entity Manager Factory created: 368ms
1 - Entity Manager Created: 1019ms
2 - Execute a simple query: 487ms
3 - indirectly execute query: 1275ms
4 - Entity manager closed: 2ms
LAST - register all services: 189ms
second run in same jvm instance of the same code
0 - Entity Manager Factory created BIS: 6ms
1 - Entity Manager Created BIS: 15ms
2 - Execute a simple query BIS: 1ms
3 - indirectly execute query BIS: 2ms
4 - Entity manager closed BIS: 1ms
JPA configuration:
//jdbc:derby:/home/laurent/MyDB;create=true
String database_url= System.getProperty("DATABASE_URL");
PersistenceProvider persistenceProvider =
Activator.getInstance().getPersistenceProvider();
if(persistenceProvider == null) {
throw new NullPointerException("Cannot retrieve a persistence provider");
}
Map<String, Object> properties = new HashMap<String, Object>();
properties.put(JDBC_URL, database_url);
properties.put(CLASSLOADER, getClass().getClassLoader());
// properties.put(DDL_GENERATION, CREATE_ONLY);
// * XXX BEGIN DEBUG EclipseLink XXX
// properties.put(LOGGING_LEVEL, "FINE");
// properties.put(LOGGING_TIMESTAMP,"false");
// properties.put(LOGGING_SESSION, "false");
// properties.put(LOGGING_THREAD, "false");
// * XXX END DEBUG EclipseLink XXX
EntityManagerFactory emf =
persistenceProvider.createEntityManagerFactory(PERSISTENCE_U NIT,
properties);
// persistence.xml
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.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_1_0.xsd">
<persistence-unit name="persistence-unit-name">
<class>Class1</class>
<class>Class2</class>
</persistence-unit>
</persistence>
|
|
|
|
Re: EntityManager life cycle in OSGi application [message #385484 is a reply to message #385483] |
Thu, 12 February 2009 16:47 |
Eclipse User |
|
|
|
Originally posted by: laurent.legoff.geensys.com
Tom Ware a écrit :
> There is a good example of how to get started with EclipseLink in
> Equinox available in our repository. It uses RCP, but the concepts are
> applicable to any Equinox Application.
>
> Both the setup part of the application and the UI use OSGi.
>
thanks tom,
I've just use this exemple for my test.This is what my first message talked about.
I use your example to write mine.
laurent
|
|
|
Powered by
FUDForum. Page generated in 0.02739 seconds