By default JDO provides a PersistenceManagerFactory (PMF) to represent a datastore. DataNucleus extends this to allow for a PMF to represent multiple datastores. This is intended for use where you have a data model for an application and maybe some classes are persisted into a different datastore. Note that this is work-in-progress and only tested for basic persist/retrieve operations using different schemas of the same datastore. Obviously if you have relations between one object in one datastore and another object in another datastore you cannot have foreign-keys (or equivalent).
You could specify the datastores to be used for the PMF like this. Here we have datanucleus.properties defining the primary datastore.
javax.jdo.option.ConnectionDriverName=com.mysql.jdbc.Driver javax.jdo.option.ConnectionURL=jdbc:mysql://127.0.0.1/nucleus?useServerPrepStmts=false javax.jdo.option.ConnectionUserName=mysql javax.jdo.option.ConnectionPassword= datanucleus.datastore.store2=datanucleus2.properties
You note that this refers to a store2, which is defined by datanucleus2.properties. So the secondary datastore is defined by
javax.jdo.option.ConnectionURL=mongodb:/nucleus
So now we need to notate which class is persisted to primary and which is persisted to secondary datastores. We do it like this, for the classes persisted to the secondary datastore.
@PersistenceCapable @Extension(vendorName="datanucleus", key="datastore", value="store2") public class MyOtherClass { ... }
So for any persistence of objects of type MyOtherClass, they will be persisted into the MongoDB secondary datastore.