Accessing MongoDB using JPA
In this recipe, we will use a JPA provider that allows us to use JPA entities to achieve object-to-document mapping with MongoDB.
Getting ready
Start the standalone server instance listening to port 27017
. This is a Java project using JPA. Familiarity with JPA and its annotations is expected, though what we will be looking at is fairly basic. Refer to the Connecting to the single node using a Java client recipe in Chapter 1, Installing and Starting the Server, to see how to set up maven if you are not aware of it. Download the DataNucleusMongoJPA
project from the bundle provided with this book. Though we will be executing the test cases from the command prompt, you can import the project to your favorite IDE to view the source code.
How to do it…
Go to the root directory of the
DataNucleusMongoJPA
project and execute the following in the shell:$ mvn clean test
This should download the necessary artifacts needed to build and run the project and execute the test cases...