Table of contents
  1. Quick Snippets
    1. Generate UUID identity
  2. Key Annotations
  3. Core
    1. io.micronaut.core.annotation
    2. Data
    3. io.micronaut.data.annotation
  4. Validation
    1. javax.validation.constraints
  5. Hibernate
  6. Lombok




Quick Snippets

Generate UUID identity


@Id
@Column(columnDefinition = "BINARY(16)")
@GeneratedValue(generator = "system-uuid", strategy = GenerationType.IDENTITY)
@GenericGenerator(name = "system-uuid", strategy = "org.hibernate.id.UUIDGenerator")
public class MyObject {
    //code
}

Key Annotations

AnnotationDefinition
@InjectUsed for dependency injection to indicate where Micronaut should inject dependencies (like @Autowired in Spring).
@SingletonDefines a class as a singleton bean, ensuring only one instance is created and used throughout the application.
@IntrospectedOptimizes a class for reflection by generating metadata at compile time for GraalVM or serialization use.
@ControllerMarks a class as an HTTP controller, responsible for handling HTTP requests and responses in a REST API.
@Get, @Post, @Put, @DeleteHTTP method-specific annotations to map requests to specific controller methods for handling HTTP GET, POST, PUT, or DELETE requests.
@ClientUsed to define a declarative HTTP client interface for making HTTP requests to external services or other applications.
@RequiresSpecifies that a bean should only be loaded if certain conditions (e.g., presence of a configuration or environment variable) are met.
@ConfigurationPropertiesMaps external configuration properties (e.g., from application.yml) to a POJO.
@ValueInjects a specific value from the application configuration (e.g., application.yml) into a field or method parameter.
@ValidatedEnables method-level validation using JSR-380 Bean Validation API (Hibernate Validator).
@NotNull, @Min, @MaxCommon validation annotations used in conjunction with @Validated for validating method parameters and properties.
@QueryValueUsed in a controller to bind query parameters in HTTP requests to method arguments.
@PathVariableBinds URI path variables to method parameters in controllers.
@BodyBinds the body of an HTTP request to a method argument in a controller, typically used for POST and PUT requests.
@ErrorHandles exceptions globally or locally within a controller, providing custom error responses.
@CacheableCaches the result of a method call to improve performance.
@ScheduledSchedules the execution of a method at a fixed rate, useful for periodic tasks like cron jobs.
@FilterDefines an HTTP filter to intercept and modify requests and responses for cross-cutting concerns (e.g., logging, authentication).
@RetryableEnables automatic retries for methods that fail due to transient issues (e.g., network errors).
@SecuredApplies security rules to restrict access to methods or controllers based on roles or authorities.
@PrimaryMarks a bean as the primary candidate for dependency injection when multiple beans of the same type exist.
@EventListenerListens for specific events and executes the annotated method when the event is published.
@HeaderAllows you to bind HTTP headers in controllers or clients to method arguments.
@CircuitBreakerApplies a circuit breaker pattern to a method to handle failures gracefully by limiting requests and preventing cascading failures.
@FactoryDefines a factory class for producing custom beans.
@PrototypeDefines a bean with a prototype scope, creating a new instance each time it is injected.
@ConfigurationMarks a class as a configuration class, allowing it to provide application-specific beans or configurations.
@TransactionalDefines a method or class as transactional, ensuring that database operations are wrapped in a transaction.
@TraceEnables distributed tracing for methods, allowing the application to track request flow across multiple services.
@FallbackDefines a fallback method that gets invoked when a @Retryable or @CircuitBreaker operation fails.
@Requires(property)Ensures that a bean is only loaded if the specified configuration property is present.

Core

io.micronaut.core.annotation

BlockingA marker annotation for methods that are blocking.
CreatorAn annotation applicable to a constructor that provides a hint as to which constructor is the primary constructor.
EntryPointEntryPoint is a meta-annotation used on other annotations to indicate that the annotated element is an entry point into the framework from the outside.
ExperimentalAnnotates a class or method as being experimental and subject to change or removal.
GeneratedA marker annotation for methods that are generated though an annotation processor.
IndexedAn annotation that can be used on types where there may be many implementations of a particular interface.
IndexesAllows Indexed to be repeatable.
InstantiatedMemberAn annotation that can be used on another annotation member that returns a class to indicate that the value of the annotation should be populated as an instance of the specified class.
InternalAnnotates a class or method regarded as internal and not for public consumption.
IntrospectedAn annotation that indicates a type should produce a BeanIntrospection at compilation time.
Introspected.IndexedAnnotationAllow pre-computed indexes for property lookups based on an annotation and a member.
NonBlockingA marker annotation for methods that are non-blocking.
NonNullA common annotation to declare that annotated elements cannot be null.
NullableA common annotation to declare that annotated elements can be null under some circumstance.
OrderAnnotation for objects that are ordered.
ReflectiveAccessDescriptive annotation that can be used to declare a field, method, constructor and types for reflective access.
TypeHintThe type hint annotation is a general annotation that can be used on interfaces to provide additional information about types used at runtime.
UsedByGeneratedCodeA marker annotation indicating that a method is used by generated code and should not be modified or removed otherwise a binary compatibility problem will be introduced.

Data

io.micronaut.data.annotation

Annotation TypeDescription
AutoPopulatedMeta annotation to identity annotations that are auto-populated by the Micronaut Data.
DataTransformerGeneric version of allowing transformations to be applied when reading or writing data to and from the a database.
DateCreatedCan be applied to date type to indicate the property should be populated when it is first inserted.
DateUpdatedCan be applied to date type to indicate the property should be populated when it was last updated.
EmbeddableAnnotation to be used on POJOs that are embeddable in MappedEntity types.
EmbeddedIdAnnotation that specifies the embedded ID.
GeneratedValueDesignates a property as a generated value.
IdDesignates a field or method that is annotated with the Id of an entity.
JoinA @Join defines how a join for a particular association path should be generated.
MappedEntityDesignates a class as being persisted.
MappedPropertyDesignates a method or field that is mapped as a persistent property.
QueryDefines the query string such as SQL, JPA-QL, Cypher etc that should be executed.
QueryHintProvides a query hint to the underlying query implementation.
RelationAnnotation used to indicate a field or method is a relation to another type.
RepositoryDesignates a type of a data repository.
RepositoryConfigurationModels compilation time configuration for the repository.
TransientAnnotation used to indicate a field or method is transient and not persisted.
TypeDefType definitions allow associated existing types with a specify DataType.
TypeRoleA type role indicates a method element in a repository that plays a role in query execution and should not be factored into query calculation but instead made available at runtime using the specified role name.
VersionDesignates a field or method that is used to version an entity.
WhereThere Where annotation allows augmenting the WHERE statement of generated queries with additional criterion.
*** In the case of using JPA only a subset of annotations is supported including the following: ***
  • Basic: @Table, @Id ,@Version, @Column, @Transient, @Enumerated

  • Embedded definition: @Embedded @EmbeddedId @Embeddable

  • Relationship mapping: @OneToMany @OneToOne @ManyToOne @ManyToMany

  • Join specification: @JoinTable @JoinColumn

  • Type converters: @Convert @Converter and AttributeConverter Interface

Validation

javax.validation.constraints

Annotation TypeDescription
AssertFalseThe annotated element must be false.
AssertFalse.ListDefines several AssertFalse annotations on the same element.
AssertTrueThe annotated element must be true.
AssertTrue.ListDefines several AssertTrue annotations on the same element.
DecimalMaxThe annotated element must be a number whose value must be lower or equal to the specified maximum.
DecimalMax.ListDefines several DecimalMax annotations on the same element.
DecimalMinThe annotated element must be a number whose value must be higher or equal to the specified minimum.
DecimalMin.ListDefines several DecimalMin annotations on the same element.
DigitsThe annotated element must be a number within accepted range.
Digits.ListDefines several Digits annotations on the same element.
EmailThe string has to be a well-formed email address.
Email.ListDefines several @Email constraints on the same element.
FutureThe annotated element must be an instant, date or time in the future.
Future.ListDefines several Future annotations on the same element.
FutureOrPresentThe annotated element must be an instant, date or time in the present or in the future.
FutureOrPresent.ListDefines several FutureOrPresent annotations on the same element.
MaxThe annotated element must be a number whose value must be lower or equal to the specified maximum.
Max.ListDefines several Max annotations on the same element.
MinThe annotated element must be a number whose value must be higher or equal to the specified minimum.
Min.ListDefines several Min annotations on the same element.
NegativeThe annotated element must be a strictly negative number (i.e.
Negative.ListDefines several Negative constraints on the same element.
NegativeOrZeroThe annotated element must be a negative number or 0.
NegativeOrZero.ListDefines several NegativeOrZero constraints on the same element.
NotBlankThe annotated element must not be null and must contain at least one non-whitespace character.
NotBlank.ListDefines several @NotBlank constraints on the same element.
NotEmptyThe annotated element must not be null nor empty.
NotEmpty.ListDefines several @NotEmpty constraints on the same element.
NotNullThe annotated element must not be null.
NotNull.ListDefines several NotNull annotations on the same element.
NullThe annotated element must be null.
Null.ListDefines several Null annotations on the same element.
PastThe annotated element must be an instant, date or time in the past.
Past.ListDefines several Past annotations on the same element.
PastOrPresentThe annotated element must be an instant, date or time in the past or in the present.
PastOrPresent.ListDefines several PastOrPresent annotations on the same element.
PatternThe annotated CharSequence must match the specified regular expression.
Pattern.ListDefines several Pattern annotations on the same element.
PositiveThe annotated element must be a strictly positive number (i.e.
Positive.ListDefines several Positive constraints on the same element.
PositiveOrZeroThe annotated element must be a positive number or 0.
PositiveOrZero.ListDefines several PositiveOrZero constraints on the same element.
SizeThe annotated element size must be between the specified boundaries (included).
Size.ListDefines several Size annotations on the same element.

Hibernate

AnnotationPurpose
@EntityDeclares an entity class (a class with its own database table an persistent identity)
@MappedSuperclassA superclass that declares common persistent fields of its @Entity subclasses
@Embeddable or @EmbeddedDeclare an embeddable class (a class without its own persistent identity or database table)
@InheritanceDefines how inheritance hierarchies should be mapped to database tables
@IdSpecifies that a field of an entity holds the persistent identity of the entity, and maps to the primary key of its table
@IdClassSpecifies a class representing the composite primary key of the entity (for entities with multiple @Id fields)
@EmbeddedIdSpecifies that a field of an entity holds its composite primary key represented as an @Embeddable class
@GeneratedValueSpecifies that an identifier is a system-generated surrogate key
@VersionSpecifies that a field of an entity holds a version number used for optimistic locking
@EnumeratedMaps a field holding an enum
@ManyToOneDeclares a many-to-one association to a second entity
@OneToOneDeclares a one-to-one association to a second entity
@OneToManyDeclares a one-to-many association to a second entity
@TableSpecifies a mapping to a database table
@SecondaryTableSpecifies a mapping to a second database table
@ColumnSpecifies a mapping to a database column
@JoinColumnSpecifies a mapping to a database foreign key
@CacheEnables second-level caching for an entity
@FormulaMaps field to SQL expression instead of a column
@CreationTimestamp, @UpdateTimestampAutomatically assign a timestamp to a field
@OptimisticLockingEnables optimistic locking for entities with no @Version field
@FilterDef and @FilterDefine a Hibernate filter
@FetchProfileDefines a Hibernate fetch profile
@GeneratedDefines a property generated by the database
@ColumnDefaultSpecifies a SQL expression used to assign a default value to a column (use in combination with @Generated(INSERT))
@GenericGeneratorSelects a custom id generator
@DynamicInsert and @DynamicUpdateGenerate SQL dynamically with only needed columns (instead of using static SQL generated at startup)
@FetchSpecifies the fetching mode for an association
@BatchSizeSpecifies the batch size for batch fetching an association
@LoaderSpecifies a named query used to fetch an entity by id (for example, when find(type, id) is called) in place of the default SQL generated by Hibernate
@SqlInsert, @SqlUpdate, @SqlDeleteSpecify custom DML for entity operations
@NaturalIdMarks a field or fields as an alternative “natural” identifier (unique key) of the entity
@NationalizedUse nchar, nvarchar, or nclob selectively for one particular column.
@ImmutableSpecifies that an entity or collection is immutable
@SortNatural or @SortComparatorMaps a SortedSet or SortedMap
@CheckDeclares a SQL check constraint to be added to DDL

Lombok

Needs to be above micronaut annotations on classpath in gradle
  annotationProcessor 'org.projectlombok:lombok:1.18.24'
For lombok to recognize micronaut annotations and inject into constructor

create lombok.config at root, insert line:

   lombok.copyableannotations += io.micronaut.core.annotation.Nullable