Questions tagged [spring-data-jpa]

Spring Data - JPA is part of the Spring Data umbrella project which makes it easy to implement JPA based repositories

Spring Data JPA, part of the larger family, makes it easy to easily implement based repositories. This module deals with enhanced support for based data access layers. It makes it easier to build Spring-powered applications that use data access technologies.

is based on the concepts of Aggregates, Aggregate Roots and Repositories. It works best if these concepts are considered when you design your domain model. You might want to look into "Advancing Enterprise DDD" to learn what that actually means.

Please note that Spring Data doesn't try to abstract over the underlying technology. This means as a user you still have to understand it. In the case of Spring Data JPA this means you need to understand JPA in order to properly work with Spring Data JPA. This applies especially to the workings of the 1st level cache.

Useful links

Popular Questions

What is Spring Data JPA (good for)

Common questions

22458 questions
158
votes
9 answers

setMaxResults for Spring-Data-JPA annotation?

I am trying to incorporate Spring-Data-JPA into my project. One thing that confuses me is how do I achieve setMaxResults(n) by annotation ? for example, my code: public interface UserRepository extends CrudRepository { …
smallufo
  • 11,516
  • 20
  • 73
  • 111
147
votes
16 answers

%Like% Query in spring JpaRepository

I would like to write a like query in JpaRepository but it is not returning anything : LIKE '%place%'-its not working. LIKE 'place' works perfectly. Here is my code : @Repository("registerUserRepository") public interface RegisterUserRepository…
sudeep cv
  • 1,901
  • 4
  • 16
  • 19
145
votes
6 answers

Is it possible to use raw SQL within a Spring Repository

I need to use raw SQL within a Spring Data Repository, is this possible? Everything I see around @Query is always entity based.
Ben
  • 60,438
  • 111
  • 314
  • 488
134
votes
9 answers

Spring Data: "delete by" is supported?

I am using Spring JPA for database access. I am able to find examples such as findByName and countByName, for which I dont have to write any method implementation. I am hoping to find examples for delete a group of records based on some…
curious1
  • 14,155
  • 37
  • 130
  • 231
129
votes
3 answers

How does Spring Data JPA differ from Hibernate for large projects?

I am having a hard time deciding if I should stick with Hibernate for a new project, or get my feet wet with JPA and the new Spring Data implementation. Is the Spring Data framework intended for large projects or small projects with modest query…
egervari
  • 22,372
  • 32
  • 121
  • 175
128
votes
22 answers

Can't Autowire @Repository annotated interface in Spring Boot

I'm developing a spring boot application and I'm running into an issue here. I'm trying to inject a @Repository annotated interface and it doesn't seem to work at all. I'm getting this error org.springframework.beans.factory.BeanCreationException:…
visst
  • 1,351
  • 2
  • 11
  • 10
128
votes
10 answers

Spring data JPA query with parameter properties

What is the simplest way of declaring a Spring data JPA query that uses properties of an input parameter as query parameters? For example, suppose I have an entity class: public class Person { @Id private long id; @Column private…
Kkkev
  • 4,716
  • 5
  • 27
  • 43
126
votes
5 answers

Spring Data JPA find by embedded object property

I want to write a Spring Data JPA repository interface method signature that will let me find entities with a property of an embedded object in that entity. Does anyone know if this is possible, and if so how? Here's my code: @Entity @Table(name =…
CorayThan
  • 17,174
  • 28
  • 113
  • 161
126
votes
6 answers

Case insensitive Query with Spring CrudRepository

With Spring CrudRepository Query; I want to select "DeviceType" entities with it's "name" property. But following query select the entitles on case sensitive manner. How I make it case insensitive way. Thanks. public interface DeviceTypeRepository…
Channa
  • 4,963
  • 14
  • 65
  • 97
123
votes
10 answers

What is the LIMIT clause alternative in JPQL?

I'm working with PostgreSQL query implementing in JPQL. This is a sample native psql query which works fine, SELECT * FROM students ORDER BY id DESC LIMIT 1; The same query in JPQL doesnt work, @Query("SELECT s FROM Students s ORDER BY s.id DESC…
Madhu
  • 2,643
  • 6
  • 19
  • 34
123
votes
1 answer

crudrepository findBy method signature with multiple in operators?

I have an Entity Class like this: @Entity @Table(name = "EMAIL") class Email{ @Id @Column(name = "Id") Long id; @Column(name = "EMAIL_ID") String emailId; @Column(name = "PIN_CODE") String pincode; } How to write findBy…
Venkata Rama Raju
  • 1,325
  • 2
  • 10
  • 15
119
votes
5 answers

Missing CrudRepository#findOne method

I am using Spring 5 in my project. Until today there was available method CrudRepository#findOne. But after downloading latest snapshot it suddenly disappeared! Is there any reference that the method is not available now? My dependency list: apply…
Andrii Abramov
  • 10,019
  • 9
  • 74
  • 96
117
votes
20 answers

Spring Data and Native Query with pagination

In a web project, using latest spring-data (1.10.2) with a MySQL 5.6 database, I'm trying to use a native query with pagination but I'm experiencing an org.springframework.data.jpa.repository.query.InvalidJpaQueryMethodException at startup. UPDATE:…
Lasneyx
  • 2,110
  • 2
  • 17
  • 21
116
votes
5 answers

Spring Data JPA difference between findBy / findAllBy

Is there any difference when using Spring Data JPA keywords between: List findBySomeCondition(); and List findAllBySomeCondition();
Nikita
  • 1,465
  • 3
  • 15
  • 17
114
votes
10 answers

Unable to find a @SpringBootConfiguration, you need to use @ContextConfiguration or @SpringBootTest(classes=...) with your test

I am using Spring Data JPA and Spring Boot. The layout of the application is this main +-- java +-- com/lapots/game/monolith +-- repository/relational +--RelationalPlayerRepository.java +-- web …
lapots
  • 12,553
  • 32
  • 121
  • 242