OSGi Community Event 2013 (http://www.osgi.org/CommunityEvent2013/Schedule)
Lightning Talk
ABSTRACT
This Lightning talk shows an example how to use use an EclipseLink composite Persistence Unit in an OSGi Bundle to seamless combine a Relational Database and NoSQL MongoDB. Furthermore it gives some best practice how to use a JPA Persistence Unit with Blueprint.
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Polyglot Persistence with OSGi - Alexander Grzesik
1. Polyglot Persistence with
OSGi
Combining relational databases
and NoSQL MongoDB with
EclipseLink
OSGi Community Event
Ludwigsburg
Eclipsecon 2013
Alexander Grzesik
3. EclipseLink composite persistence unit
Since 2.3
NoSQL
SQL
From: http://wiki.eclipse.org/EclipseLink/Examples/JPA/Composite
Eclipsecon 2013
Polyglot Persistence with OSGi
4. SQL Persistence Unit
• Plain JPA PU jar
• PU‘s must use same transaction strategy
<persistence-unit name="persistence-test-sql"
transaction-type="RESOURCE_LOCAL">
<non-jta-data-source>jdbc/test</non-jta-data-source>
• Class Mappings
<class>medisite.eclipsecon.entities.sql.BMIUser</class>
• Member PU setting
<property name="eclipselink.composite-unit.member"
value="true"/>
• PU specific settings
<property name="eclipselink.target-database"
value="POSTGRESQL"/>
…
Eclipsecon 2013
Polyglot Persistence with OSGi
5. NoSQL Persistence Unit
• EclipseLink NoSQL support for
– MongoDB
– OracleNoSQL
• Configure like SQL PU
<persistence-unit name="persistence-test-nosql"
transaction-type="RESOURCE_LOCAL">
<class>medisite.eclipsecon.entities.nosql.BMIRecord</class>
…
<property name="eclipselink.composite-unit.member"
value="true"/>
Eclipsecon 2013
Polyglot Persistence with OSGi
6. MongoDB Configuration
• Tell the PU it uses MongoDB
<property name="eclipselink.target-database"
value="org.eclipse.persistence.nosql.adapters.mongo.
MongoPlatform"/>
<property name="eclipselink.nosql.connection-spec"
value="org.eclipse.persistence.nosql.adapters.mongo.
MongoConnectionSpec"/>
• Configure Connection
<property name="eclipselink.nosql.property.mongo.host"
value="localhost"/>
<property name="eclipselink.nosql.property.mongo.port“
value="27017"/>
<property name="eclipselink.nosql.property.mongo.db“
value="test"/>
Eclipsecon 2013
Polyglot Persistence with OSGi
7. Mapping NoSQL Entities
• Add @NoSQL Annotation
@Entity
@NoSql(dataFormat = DataFormatType.MAPPED)
public class BMIRecord {
@Basic
private String name;
@ElementCollection
private List<BMIResult> bmiResults;
@OneToOne()
private BMIUser user;
• Embeded entity
@Embeddable
@NoSql(dataFormat = DataFormatType.MAPPED)
public class BMIResult {
…
Eclipsecon 2013
Polyglot Persistence with OSGi
8. Composite Persistence Unit
• Defines visible PU name
<persistence-unit name="persistence-composite" transactiontype="RESOURCE_LOCAL">
• Included Member PUs
<jar-file>medisite.eclipsecon.pu-nosql-0.0.1.jar</jar-file>
<jar-file>medisite.eclipsecon.pu-sql-0.0.1.jar</jar-file>
• Composite PU setting
<property name="eclipselink.composite-unit" value="true"/>
• Settings for all PUs
<property name="eclipselink.logging.level" value="FINEST"/>
<property name="eclipselink.target-server" value="SunAS9"/>
Eclipsecon 2013
Polyglot Persistence with OSGi
10. Summary
• No JTA transactions
• No referential integrity between DBs
• Not all Eclipselink features are supported:
Persistence Unit Properties for Composite Pus
• Transparent combination of different databases
• Use JPA API
• Works as OSGi persistence bundle
• Blueprint integration via Aries JPA
Eclipsecon 2013
Polyglot Persistence with OSGi
12. Questions ?
More on OSGi, Persistence and Cloud:
Tomorrow 11:15
TRESOR: The modular cloud - Building a domain specific
cloud platform with OSGi
Eclipsecon 2013
Polyglot Persistence with OSGi