Notice: This Wiki is now read only and edits are no longer possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.
EclipseLink/UserGuide/JPA/Advanced JPA Development/NoSQL/Persistence Units
EclipseLink JPA
EclipseLink | |
Website | |
Download | |
Community | |
Mailing List • Forums • IRC • mattermost | |
Issues | |
Open • Help Wanted • Bug Day | |
Contribute | |
Browse Source |
Native API
NoSQL Persistence Units
NoSQL persistence units are configured the same as JPA persistence units. The persistence.xml
is used to define the persistence unit. NoSQL persistence units can be application managed, JTA managed, injected, or created through Persistence
the same as regular JPA persistence units. NoSQL persistence units do have some specific persistence unit properties that are required, and have some limitations.
NoSQL defines the following persistence unit properties:
-
"eclipselink.nosql.connection-spec"
- this specifies an EISConnectionSpec class name that defines how to connect to the NoSQL data-source. -
"eclipselink.nosql.connection-factory"
- this specifies the JNDI name of a JCA ConnectionFactory, or a JCA ConnectionFactory class name that connects to the NoSQL data-source. -
"eclipselink.nosql.property."
- this prefix is used to pass driver specific properties to the NoSQL connection spec. -
"eclipselink.target-database"
- this is used to set the NoSQL platform class, or use"org.eclipse.persistence.eis.EISPlatform"
for a generic platform.
NoSQL persistence units have the following restrictions:
-
<jta-data-source>
,<non-jta-data-source>
- these are not supported, as they refer to JDBC DataSources. -
JTA
- JTA managed persistence units are supported, but XA transactions may not be provided unless the NoSQL JCA resource adapter supports JTA. -
"javax.jdbc."
,"eclipselink.jdbc."
- JDBC specific properties are not supported as NoSQL does not use JDBC.
NoSQL Platforms
EclipseLink provides the following NoSQL platforms and connection specs. To use a NoSQL platform you must set both the "eclipselink.nosql.connection-spec"
to the connection spec class name and the "eclipselink.target-database"
to the platform class name. Each NoSQL platform also supports platform specific properties that can be set using "eclipselink.nosql.property."
.
Property | Value |
"eclipselink.target-database"
|
"org.eclipse.persistence.nosql.adapters.mongo.MongoPlatform"
|
"eclipselink.connection-spec"
|
"org.eclipse.persistence.nosql.adapters.mongo.MongoConnectionSpec"
|
"eclipselink.nosql.property.mongo.host"
|
comma separated list of MongoDB hosts |
"eclipselink.nosql.property.mongo.port"
|
comma separated list of MongoDB host's ports |
"eclipselink.nosql.property.mongo.db"
|
MongoDB database |
MongoDB persistence.xml example
<persistence 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 persistence_2_0.xsd" version="2.0"> <persistence-unit name="acme" transaction-type="RESOURCE_LOCAL"> <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider> <exclude-unlisted-classes>false</exclude-unlisted-classes> <properties> <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"/> <property name="eclipselink.nosql.property.mongo.port" value="27017, 27017"/> <property name="eclipselink.nosql.property.mongo.host" value="host1, host2"/> <property name="eclipselink.nosql.property.mongo.db" value="acme"/> </properties> </persistence-unit> </persistence>