# Enforcing Java Record Invariants With Bean Validation

DevFeed: [Enforcing Java Record Invariants With Bean Validation](<https://devfeed.tech/articles/enforcing-java-record-invariants-with-bean-validation-18812.md>)

Original publisher: [Read original article](<https://www.morling.dev/blog/enforcing-java-record-invariants-with-bean-validation/>)

Published: 2020-01-20T16:30:00Z

Content type: tutorial

Language: en

Sources: [Gunnar Morling](<https://devfeed.tech/sources/gunnar-morling.md>)

Topics: [Java](<https://devfeed.tech/topics/java.md>), [data](<https://devfeed.tech/topics/data.md>)

Tags: [classes](<https://devfeed.tech/tags/classes.md>), [implementation](<https://devfeed.tech/tags/implementation.md>), [java](<https://devfeed.tech/tags/java.md>), [validation](<https://devfeed.tech/tags/validation.md>)

## AI overview

This tutorial explains how to enforce invariants on Java record types using annotation-based constraints from the Bean Validation API. It describes record components, class invariants, and validation during construction, including the role of method validation for immutable records.

## Source excerpt

Table of Contents Record Invariants and Bean Validation Implementation Advantages Limitations Wrap-Up Record types are one of the most awaited features in Java 14; they promise to "provide a compact syntax for declaring classes which are transparent holders for shallowly immutable data". One example where records should be beneficial are data transfer objects (DTOs), as e.g. found in the remoting layer of enterprise applications. Typically, certain rules should be applied to the attributes of such DTO, e.