-
Notifications
You must be signed in to change notification settings - Fork 87
guide devon4j spring repository
devonfw-core edited this page Nov 21, 2022
·
5 revisions
Table of Contents
|
Warning
|
Hey there! Seems like you are still using the documentation of our legacy Java repository. Since it won’t be maintained anymore, we recommend you to checkout the new Java page here. |
In devon4j-spring, spring-data-jpa is provided via devon4j-starter-spring-data-jpa extension, which provides advanced integration (esp. for QueryDSL).
Spring Data uses a fragment approach to implement custom functionality for repositories. For Spring applications, devon4j provides a solution that works without this fragment approach.
The repository must extend DefaultRepository, which uses GenericRepositoryImpl as implementation. The QueryUtil helper class provides methods to support pagination and query creation.
|
Warning
|
Hey there! Seems like you are still using the documentation of our legacy Java repository. Since it won’t be maintained anymore, we recommend you to checkout the new Java page here. |
<dependency>
<groupId>com.devonfw.java.starters</groupId>
<artifactId>devon4j-starter-spring-data-jpa</artifactId>
</dependency>|
Warning
|
Hey there! Seems like you are still using the documentation of our legacy Java repository. Since it won’t be maintained anymore, we recommend you to checkout the new Java page here. The following example shows how to write such a repository. The example has the same functionality as the example in the Spring Data guide: |
public interface ExampleRepository extends DefaultRepository<ExampleEntity> {
@Query("SELECT example FROM ExampleEntity example" //
+ " WHERE example.name = :name")
List<ExampleEntity> findByName(@Param("name") String name);
@Query("SELECT example FROM ExampleEntity example" //
+ " WHERE example.name = :name")
Page<ExampleEntity> findByNamePaginated(@Param("name") String name, Pageable pageable);
default Page<ExampleEntity> findByCriteria(ExampleSearchCriteriaTo criteria) {
ExampleEntity alias = newDslAlias();
JPAQuery<ExampleEntity> query = newDslQuery(alias);
String name = criteria.getName();
if ((name != null) && !name.isEmpty()) {
QueryUtil.get().whereString(query, $(alias.getName()), name, criteria.getNameOption());
}
return QueryUtil.get().findPaginated(criteria.getPageable(), query, false);
}
}|
Warning
|
Hey there! Seems like you are still using the documentation of our legacy Java repository. Since it won’t be maintained anymore, we recommend you to checkout the new Java page here. You can also read the JUnit test-case DefaultRepositoryTest that is testing an example FooRepository. |
|
Warning
|
Hey there! Seems like you are still using the documentation of our legacy Java repository. Since it won’t be maintained anymore, we recommend you to checkout the new Java page here.
In case you need auditing, you only need to extend DefaultRevisionedRepository instead of DefaultRepository. The auditing methods can be found in GenericRevisionedRepository.
|
This documentation is licensed under the Creative Commons License (Attribution-NoDerivatives 4.0 International).
