Questions tagged [spring-repositories]

This tag is for question related to the use of Spring Data repository abstraction APIs.

This tag is for question related to the use of Spring Data repository abstraction APIs.

Spring Data repository abstraction is a data access layer abstraction for integration of various persistence stores, such as Java Persistence API (JPA).

311 questions
100
votes
5 answers

Check date between two other dates spring data jpa

I have this model: public class Event { private String name; private Date start; private Date end; } and repository as @Repository public interface EventRepository extends JpaRepository { List
Don Jose
  • 1,448
  • 2
  • 13
  • 27
43
votes
4 answers

How to get all results in one page using Spring Data Pagination

I want to get all the results in single page, I've tried with Pageable p = new PageRequest(1, Integer.MAX_VALUE); return customerRepository.findAll(p); Above is not working, is there any methods to achieve this? Seems like it cannot be achieved…
29
votes
2 answers

Spring data repository's method to find by the field of a field

I've two entities, a user and a registered user. A registered user has a field of type user. I would like to have a method in the spring data repository related to this registered user entity to search all registered users by the username of the…
nbro
  • 15,395
  • 32
  • 113
  • 196
15
votes
1 answer

Get total count rows for Pageable custom query in Spring repository

I implement pagination like this: List products = productRepository.findAllProducts(productsRequest.getInitiatorType(), "ACTIVE", new PageRequest(page, 100, Sort.Direction.DESC, "insertDate")); But how can I get Total size for this…
ip696
  • 6,574
  • 12
  • 65
  • 128
12
votes
3 answers

How to distinct counting with Spring JPA Repository

How do I do a distinct counting with Spring Data JPA? I do not want to use the @Query annotation. The equivalent sql query would be: SELECT COUNT(DISTINCT rack) FROM store WHERE id = 10001; I tried by writing the following query, but it isn't…
Benimo
  • 167
  • 1
  • 1
  • 7
11
votes
3 answers

How to query JPA LocalDateTime field with a LocalDate value?

I search for a way to get a list of Objects created on a certain LocalDateTime date saved in the Postgresql database in a field of type TIMESTAMPTZ. To do so, I tried to use JpaRepository: List findByCreationDate(LocalDate date); But I get…
user3450862
  • 379
  • 1
  • 6
  • 22
11
votes
1 answer

spring crud repository find top n Items by field A and field B in list order by field C

I have in a Spring Repo something like this: findTop10ItemsByCategIdInOrderByInsertDateDesc(List ids) I want the first 10 items where category id in list of ids ordered by insert date. Another similar query:…
bogdan.rusu
  • 901
  • 4
  • 21
  • 41
10
votes
2 answers

Generate automatically Spring Data Repositories from JPA entities

I have a lot of JPA entities automatically created from a relational database schema. Is there any way to generate also there corresponding Spring Data Repositories (Repository interfaces)?
CPA
  • 2,923
  • 4
  • 30
  • 52
9
votes
1 answer

Declare repository providing the artifact, see the documentation at

Task :app:checkDebugAarMetadata FAILED Execution failed for task ':app:checkDebugAarMetadata'. Could not resolve all files for configuration ':app:debugRuntimeClasspath'. Could not find com.example.newsapplication:egUsePieRotation:. Required…
9
votes
1 answer

SpringData Redis Repository with complex key

We try to use the Spring Data CrudRepository in our project to provide persistency for our domain objects. For a start I chose REDIS as backend since in a first experiment with a CrudRepository it seemd, getting it…
9
votes
1 answer

How to select latest record in group using JPQL in Spring JpaRepository?

In a SpringBoot Microservice, I am trying to select the latest record for an actor for each mean_of_payment_id. To achieve this, selecting actor content for actor_id where created_date is equaled to the subset of the nested query of…
ajkush
  • 587
  • 2
  • 11
  • 25
7
votes
3 answers

Find entity by exact matching in collection

I have entity like this: @Getter @Setter @Entity public class Conversation extends AbstractEntity{ @ElementCollection @Column(name = "user_id", nullable = false) @CollectionTable(name = "conversation_user", joinColumns =…
Denis Stephanov
  • 4,563
  • 24
  • 78
  • 174
7
votes
1 answer

Any way to use the `@Procedure` annotation without an entity?

So I'd like a "Void-Repository" through which to gain access to stored procedures that are not necessarily operation on entities. @Repository public interface StoredProceduresRepository extends CrudRepository { …
User1291
  • 7,664
  • 8
  • 51
  • 108
7
votes
3 answers

When to use Spring's @Repository annotation?

When reading about creating custom queries in Spring, I noticed that none of the classes (UserRepositoryCustom, UserRepositoryCustomImpl, UserRepository) use the @Repository annotation. I was surprised by this, because usually all the Spring…
Snackoverflow
  • 5,332
  • 7
  • 39
  • 69
6
votes
2 answers

How to use JPA Repositories without Spring Boot

I have an existing spring 4 project (mvc, jdbc etc) and I tried to port it to spring boot and I can't. (many dependencies troubles, no one can't explain how I can do that). But now I just want to use Spring Data JPA in existing project. That is a…
1
2 3
20 21