Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "SMILA/Documentation/General JPA Configuration in SMILA"

m (Why does a new DB involve so much configuration ?: renamed section)
(Configuration)
 
(One intermediate revision by one other user not shown)
Line 22: Line 22:
 
</source>
 
</source>
  
See  the [Using_EclipseLink_JPA_Extensions_(ELUG)#Using_EclipseLink_JPA_Extensions_for_JDBC|EL documentation] for an in depth discussion.
+
See  the [[Using_EclipseLink_JPA_Extensions_(ELUG)#Using_EclipseLink_JPA_Extensions_for_JDBC|EL documentation]] for an in depth discussion.
  
 
This page will discuss only a few common use cases.
 
This page will discuss only a few common use cases.
Line 113: Line 113:
 
In SMILA we uses the file {{path|META-INF/orm.xml}} to define the mapping of the Java classes to the database. If you get errors when creating the tables it might be due to the default mapping that is in place.
 
In SMILA we uses the file {{path|META-INF/orm.xml}} to define the mapping of the Java classes to the database. If you get errors when creating the tables it might be due to the default mapping that is in place.
  
Also check that otherwise the EL default mappings that are defined in the class given in {{code|eclipselink.target-database}} match your needs.  For instance this was not the case for Derby! It defines for byte[] a BLOB(64000) which is not sufficient in binarystorage, so we had to just use BLOB.  
+
Also check that otherwise the EL default mappings that are defined in the class given in {{code|eclipselink.target-database}} match your needs.  For instance this was not the case for Derby! It defines for byte[] a BLOB(64000) which is not sufficient in binarystorage, so we had to just use BLOB.
  
 
== Limitations and Known Issues ==
 
== Limitations and Known Issues ==
Line 131: Line 131:
 
This warning can be ignored as well and is cause by the {{code|eclipselink.ddl-generation}} property. The default value , causes that the table(s) are attempted to be created at startup of the bundle. If you ran SMILA before then this tables already exist, providing that you didnt drop the DB, and hence the error.
 
This warning can be ignored as well and is cause by the {{code|eclipselink.ddl-generation}} property. The default value , causes that the table(s) are attempted to be created at startup of the bundle. If you ran SMILA before then this tables already exist, providing that you didnt drop the DB, and hence the error.
  
=== Why does a another DB provider involve so much configuration ? ===
+
=== Why does another DB provider involve so much configuration ? ===
 
unfortunately the world is not perfect and the technologies that we use impose those on us until this is fixed there. See
 
unfortunately the world is not perfect and the technologies that we use impose those on us until this is fixed there. See
 
* http://www.eclipse.org/forums/index.php?t=msg&th=155948&start=0&S=09a587abaac560de95f6274996584c7b
 
* http://www.eclipse.org/forums/index.php?t=msg&th=155948&start=0&S=09a587abaac560de95f6274996584c7b
 
* http://www.eclipse.org/forums/index.php?t=msg&th=156088&start=0&S=09a587abaac560de95f6274996584c7b
 
* http://www.eclipse.org/forums/index.php?t=msg&th=156088&start=0&S=09a587abaac560de95f6274996584c7b

Latest revision as of 12:10, 23 January 2012


Overview

This page explains how to configure the general JPA aspects of bundles that use JPA to store information. At the moment EclipseLink (EL) is used as the JPA Provider.

Configuration

To configure JPA you will at least have to edit the <configuration>/<bundlename>/persistence.properties. These properties are passed to javax.persistence.Persistence.createEntityManagerFactory(String, Map) to initialize EclipseLink .

These are the default values as shipped, although the URL for eclipselink.jdbc.url will vary for each bundle:

# EclipseLink properties
eclipselink.logging.level=INFO
eclipselink.target-server=None
eclipselink.target-database=org.eclipse.persistence.platform.database.DerbyPlatform
eclipselink.jdbc.driver=org.apache.derby.jdbc.EmbeddedDriver
eclipselink.jdbc.url=jdbc:derby:workspace/.metadata/.plugins/org.eclipse.smila.binarystorage.persistence.jpa/binarystorage;create=true
eclipselink.jdbc.password=smila
eclipselink.jdbc.user=smila
eclipselink.ddl-generation=create-tables

See the EL documentation for an in depth discussion.

This page will discuss only a few common use cases.


Configuring usage of another database vendor

This consists of several steps due to some limitiations of JPA and/or EL:

persistence.properties

Here you need to specify at least the values for the new vendor as set forth in its documentation for your setup. The example below shows it for an MSSQL 2005 setup.

eclipselink.target-database=org.eclipse.persistence.platform.database.SQLServerPlatform
eclipselink.jdbc.driver=com.microsoft.sqlserver.jdbc.SQLServerDriver
eclipselink.jdbc.url=jdbc:sqlserver://lh:1433;DatabaseName=smila

including the JDBC driver

The more correct way to do this is to provide a bundle for the driver and export the package that contains the Driver Class. See the relevant PDE documentation on how this is accompished.

This bundle then must be imported in the <plugins>/<bundle>/META-INF/MANIFEST.MF, e.g. like so:

Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: BinaryStorage Persistence Jpa Plug-in
Bundle-SymbolicName: org.eclipse.smila.binarystorage.persistence.jpa
Bundle-Version: 0.5.0
Bundle-Vendor: empolis GmbH
Import-Package: javax.persistence;version="1.99.0",
 org.apache.commons.io;version="1.4.0",
 org.apache.commons.logging;version="1.0.4",
 org.apache.derby.jdbc;version="10.5.1.1",
 com.microsoft.sqlserver.jdbc;version="1.0.0",
 org.eclipse.smila.binarystorage;version="0.5.0",
 org.eclipse.smila.binarystorage.config;version="0.7.0",
 org.eclipse.smila.binarystorage.persistence;version="0.7.0",
 org.eclipse.smila.utils.config;version="0.5.0"
JPA-PersistenceUnits: SmilaBinaryObject
Eclipse-RegisterBuddy: org.eclipse.smila.binarystorage.impl
Export-Package: org.eclipse.smila.binarystorage.persistence.jpa;version="0.5.0"

In this example there was a SQL Server JDBC bundle created that exports the package com.microsoft.sqlserver.jdbc which package then is imported here.

Alternativly, for a quick test or hack you my just copy the driver.jar to a folder of the bundle using JPA and put it on the bundle's classpath like so:

Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: RecordStorage Impl Plug-in (Incubation)
Bundle-SymbolicName: org.eclipse.smila.recordstorage.impl
Bundle-Version: 0.5.0
Bundle-Vendor: empolis GmbH
Import-Package: javax.persistence;version="1.99.0",
 javax.persistence.spi;version="1.99.0",
 org.apache.commons.io,
 org.apache.commons.logging,
 org.apache.derby.jdbc;version="10.4.1.3",
 org.eclipse.persistence.annotations,
 org.eclipse.persistence.config,
 org.eclipse.persistence.expressions,
 org.eclipse.persistence.internal.expressions,
 org.eclipse.persistence.jpa,
 org.eclipse.persistence.queries,
 org.eclipse.persistence.sessions,
 org.eclipse.smila.datamodel.id;version="0.5.0",
 org.eclipse.smila.datamodel.id.impl;version="0.5.0",
 org.eclipse.smila.datamodel.record;version="0.5.0",
 org.eclipse.smila.datamodel.record.impl;version="0.5.0",
 org.eclipse.smila.recordstorage;version="0.5.0",
 org.eclipse.smila.utils.collections,
 org.eclipse.smila.utils.config;version="0.5.0",
 org.osgi.framework;version="1.4.0",
 org.osgi.service.component;version="1.0.0"
Service-Component: OSGI-INF/recordstorage.xml
JPA-PersistenceUnits: SmilaRecord
Export-Package: org.eclipse.smila.recordstorage.util;version="0.5.0"
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Bundle-ClassPath: .,META-INF/sqljdbc4.jar

Note: Some JDBC drivers need java 1.6 while others need 1.5. Since SMILA runs with 1.6 make sure it is supported!

Correcting Datatypes and lengths

In SMILA we uses the file META-INF/orm.xml to define the mapping of the Java classes to the database. If you get errors when creating the tables it might be due to the default mapping that is in place.

Also check that otherwise the EL default mappings that are defined in the class given in eclipselink.target-database match your needs. For instance this was not the case for Derby! It defines for byte[] a BLOB(64000) which is not sufficient in binarystorage, so we had to just use BLOB.

Limitations and Known Issues

Warning: No suitable driver found

The log contains entries such as:

[EL Warning]: 2009.10.17 09:31:39.085--ServerSession(16634203)--java.sql.SQLException: No suitable driver found for jdbc:sqlserver://lh:1433;DatabaseName=smila

These log entries can be ignored. They are caused by EL when iterating over all possible drivers to take the specified connecction. Finally it will find one that works if configiation is correct otherwise.

Warning: table XXX exists already

This warning can be ignored as well and is cause by the eclipselink.ddl-generation property. The default value , causes that the table(s) are attempted to be created at startup of the bundle. If you ran SMILA before then this tables already exist, providing that you didnt drop the DB, and hence the error.

Why does another DB provider involve so much configuration ?

unfortunately the world is not perfect and the technologies that we use impose those on us until this is fixed there. See

Copyright © Eclipse Foundation, Inc. All Rights Reserved.