-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
90 additions
and
20 deletions.
There are no files selected for viewing
60 changes: 60 additions & 0 deletions
60
buildSrc/src/main/java/io/micronaut/guides/feature/HibernateJpaReplacement.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
* Copyright 2017-2022 original authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.micronaut.guides.feature; | ||
|
||
import io.micronaut.context.annotation.Replaces; | ||
import io.micronaut.starter.application.ApplicationType; | ||
import io.micronaut.starter.application.generator.GeneratorContext; | ||
import io.micronaut.starter.build.dependencies.MicronautDependencyUtils; | ||
import io.micronaut.starter.feature.Category; | ||
import io.micronaut.starter.feature.FeatureContext; | ||
import io.micronaut.starter.feature.database.jdbc.JdbcFeature; | ||
import io.micronaut.starter.feature.migration.MigrationFeature; | ||
import io.micronaut.starter.feature.database.*; | ||
import jakarta.inject.Singleton; | ||
|
||
@Replaces(HibernateJpa.class) | ||
@Singleton | ||
public class HibernateJpaReplacement extends HibernateJpa { | ||
|
||
private static final String ARTIFACT_ID_MICRONAUT_DATA_TX_HIBERNATE = "micronaut-data-tx-hibernate"; | ||
private static final String ARTIFACT_ID_MICRONAUT_HIBERNATE_JPA = "micronaut-hibernate-jpa"; | ||
private static final String ARTIFACT_ID_MICRONAUT_DATA_MODEL = "micronaut-data-model"; | ||
|
||
public HibernateJpaReplacement(JdbcFeature jdbcFeature) { | ||
super(jdbcFeature); | ||
} | ||
|
||
@Override | ||
public void apply(GeneratorContext generatorContext) { | ||
generatorContext.getConfiguration().put(JPA_HIBERNATE_PROPERTIES_HBM2DDL, | ||
generatorContext.getFeatures().hasFeature(MigrationFeature.class) ? Hbm2ddlAuto.NONE.toString() : | ||
Hbm2ddlAuto.UPDATE.toString()); | ||
addDependencies(generatorContext); | ||
} | ||
|
||
protected void addDependencies(GeneratorContext generatorContext) { | ||
generatorContext.addDependency(MicronautDependencyUtils.sqlDependency() | ||
.artifactId(ARTIFACT_ID_MICRONAUT_HIBERNATE_JPA) | ||
.compile()); | ||
generatorContext.addDependency(MicronautDependencyUtils.dataDependency() | ||
.artifactId(ARTIFACT_ID_MICRONAUT_DATA_TX_HIBERNATE) | ||
.compile()); | ||
generatorContext.addDependency(MicronautDependencyUtils.dataDependency() | ||
.artifactId(ARTIFACT_ID_MICRONAUT_DATA_MODEL) | ||
.compile()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
To mark the transaction demarcations, we use the https://jakarta.ee/specifications/transactions/2.0/apidocs/jakarta/transaction/transactional[Jakarta jakarta.transaction.Transactional annotation]. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,13 @@ | ||
Micronaut validation is built on the standard framework – https://www.jcp.org/en/jsr/detail?id=380[JSR 380], also known as Bean Validation 2.0. | ||
https://micronaut-projects.github.io/micronaut-validation/snapshot/guide/[Micronaut validation] is built on the standard framework – https://www.jcp.org/en/jsr/detail?id=380[JSR 380], also known as Bean Validation 2.0. Micronaut Validation has built-in support for validation of beans that are annotated with `jakarta.validation` annotations. | ||
|
||
Hibernate Validator is a reference implementation of the validation API. Micronaut https://docs.micronaut.io/latest/guide/#beanValidation[has built-in support for validation of beans] that are annotated with `javax.validation` annotations. | ||
To use Micronaut Validation, you need the following dependencies: | ||
|
||
:dependencies: | ||
|
||
dependency:micronaut-validation-processor[groupId=io.micronaut.validation,scope=annotationProcessor] | ||
dependency:micronaut-validation[groupId=io.micronaut.validation] | ||
|
||
:dependencies: | ||
|
||
Alternatively, you can use https://micronaut-projects.github.io/micronaut-hibernate-validator/latest/guide/[Micronaut Hibernate Validator], which uses https://hibernate.org/validator/[Hibernate Validator]; a reference implementation of the validation API. | ||
|
||
The necessary dependencies are included by default when creating a new application, so you don't need to add anything else. |