Skip to content

Example of a Micronaut application using Micronaut Data JDBC (without ORM) leveraging immutable Kotlin data classes.

Notifications You must be signed in to change notification settings

abedurftig/micronaut-data-id-example

Folders and files

NameName
Last commit message
Last commit date
May 7, 2021
May 7, 2021
Aug 30, 2021
May 7, 2021
Aug 30, 2021
May 7, 2021
May 7, 2021
May 7, 2021
May 7, 2021
May 7, 2021
May 7, 2021

Repository files navigation

Micronaut Data Id Example

I wanted to play with Micronaut 2.5 and the latest changes in Micronaut Data allowing to work with immutable Kotlin data classes.

Can I use a non-nullable Long as identifier when creating an entity and what happens when Micronaut Data JDBC repository saves this entity to the DB?

The answer: An entity is instantiated with some random id (for ex. Long.Max). When you call the JDBC repository save method it will return a copy of the object, but the id will match the DB primary key.

Required

  • JDK 11
  • Docker

Tools / Software

  • Micronaut 2.5.1
  • Micronaut Gradle Plugin
  • Kotlin
  • Java 11
  • Testcontainers with Postgresql
  • Flyway

Implementation Details

Most interesting things can be found in the MicronautDataIdExampleTest.kt file.

  • Immutable Kotlin data class annotated with MappedEntity with id generated by a DB sequence
  • For testcontainer configuration see application-test.yml

About

Example of a Micronaut application using Micronaut Data JDBC (without ORM) leveraging immutable Kotlin data classes.

Topics

Resources

Stars

Watchers

Forks

Languages