Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Polyglot Persistence with OSGi - Alexander Grzesik


Published on

OSGi Community Event 2013 (

Lightning Talk

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.

Published in: Technology
  • Be the first to comment

  • Be the first to like this

Polyglot Persistence with OSGi - Alexander Grzesik

  1. 1. Polyglot Persistence with OSGi Combining relational databases and NoSQL MongoDB with EclipseLink OSGi Community Event Ludwigsburg Eclipsecon 2013 Alexander Grzesik
  2. 2. Polyglot Persistence
  3. 3. EclipseLink composite persistence unit Since 2.3 NoSQL SQL From: Eclipsecon 2013 Polyglot Persistence with OSGi
  4. 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="" value="POSTGRESQL"/> … Eclipsecon 2013 Polyglot Persistence with OSGi
  5. 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. 6. MongoDB Configuration • Tell the PU it uses MongoDB <property name="" 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="" value="localhost"/> <property name="“ value="27017"/> <property name="“ value="test"/> Eclipsecon 2013 Polyglot Persistence with OSGi
  7. 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. 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="" value="SunAS9"/> Eclipsecon 2013 Polyglot Persistence with OSGi
  9. 9. Composite PU MANIFEST: Embedded-Artifacts: medisite.eclipsecon.pu-sql-0.0.1.jar, medisite.eclipsecon.pu-nosql-0.0.1.jar Export-Package: medisite.eclipsecon.entities.sql;uses:="javax.persistence";versi on="0.0.1", medisite.eclipsecon.entities.nosql; uses:="org.eclipse.persistence.nosql.annotations,javax.persisten ce,medisite.eclipsecon.entities.sql";version="0.0.1" Import-Package: javax.persistence;version="[2.1,3)", org.eclipse.persistence.jpa;version="[2.5,3)", org.eclipse.persistence.nosql.adapters.mongo;version="[2.5,3)", org.eclipse.persistence.nosql.annotations;version="[2.5,3)", org.eclipse.persistence.platform.server.sunas;version="[2.5,3)", com.mongodb,… JPA-PersistenceUnits: persistence-test Meta-Persistence: META-INF/persistence.xml Eclipsecon 2013 Polyglot Persistence with OSGi
  10. 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
  11. 11. Further Information • de/JPA/Advanced_JPA_Development/Co mposite_Persistence_Units • s/PolyglotPersistence • Contact me: Eclipsecon 2013 Polyglot Persistence with OSGi
  12. 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