JPA with the business framework   JPA with the business framework

While you can do plain JPA by injecting EntityManager anywhere, it is better to define an architectural layer where you encapsulate persistence-related operations. In the business framework, persistence is confined to Repositories. JPA repository Default JPA repository The JPA add-on will provide a default JPA repository implementation for every aggregate that does not have a custom one. Two cases may occur: You don’t have any custom repository interface an particular aggregate.

MongoDB   Morphia

Morphia is an Object/Document mapper. It provides annotation-based POJO mapping, and fluent query/update APIs. SeedStack MongoDb add-on provides a module for Morphia.

JPA, step-by-step

This guide details step-by-step how to configure JPA in SeedStack, to access an existing relational database.

Flyway

SeedStack Flyway add-on provides support for automatic database migration through Flyway. For more information about Flyway: https://flywaydb.org/documentation/ Dependency Maven Gradle <dependency> <groupId>org.seedstack.addons.flyway</groupId> <artifactId>flyway</artifactId><version>2.0.0</version> </dependency> Specifying versions manually is error-prone, use dependency management instead. Show version dependencies { compile("org.seedstack.addons.flyway:flyway:2.0.0") } Configuration To enable database migration, a properly configured datasource is required: jdbc: datasources: someDatasource: url: jdbc:hsqldb:mem:somedb With only this configuration, the Flyway add-on will lookup for SQL migration scripts in the db/migration/<dsName> classpath location and if it finds any, will apply the necessary scripts to upgrade the database to the latest version.

MongoDB

SeedStack MongoDB add-on provides integration of MongoDB Java clients your application to connect with MongoDB instances.

Persistence

Now that we have a domain model, we would like to use some persistence with it. In Domain-Driven Design, persistence is done with Repositories which work on whole aggregates. We need some data first! To be able to test this, we need some sample data. A class implementing LifecycleListener will provide the opportunity to insert data at application startup. In the package infrastructure, create a SampleDataGenerator class: package org.generated.project.infrastructure; import javax.

Repositories

A repository is responsible for consistently storing and retrieving a whole aggregate.
It has a simple collection-like global interface and optionally domain-specific methods.