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
57
votes
3 answers

Spring data query where column is null

Suppose I have entities (getters/setters and various details omitted for brevity): @Entity class Customer{ ... @OneToMany(cascade = CascadeType.ALL, mappedBy = "customer") Collection coupons; } @Entity class Coupon{ ... …
lrkwz
  • 6,105
  • 3
  • 36
  • 59
56
votes
1 answer

Why has javax.persistence-api been replaced by jakarta.persistence-api in spring data jpa starter?

I've recently started to learn spring boot, data jpa. As I can see from this, the spring boot data jpa starter uses jakarta.persistence-api instead of javax.persistence-api: spring-boot-starter-data-jpa ... …
SternK
  • 11,649
  • 22
  • 32
  • 46
56
votes
4 answers

How do I stop spring data JPA from doing a SELECT before a save()?

We are writing a new app against an existing database. I'm using Spring Data JPA, and simply doing a MyRepository.save() on my new entity, using MyRepository extends CrudRepository I've noticed in the logs that hibernate is…
user26270
  • 6,904
  • 13
  • 62
  • 94
56
votes
2 answers

Can I combine a @Query definition with a Specification in a Spring Data JPA repository method?

Is it possible to use both @Query annotation and specification in one repository method? For example I'd like to have a method like this: @Query(value="SELECT e from EMPLOYEE where firstName <> ?1") public Page
woytech
  • 701
  • 1
  • 6
  • 15
56
votes
12 answers

How to use Spring managed Hibernate interceptors in Spring Boot?

Is it possible to integrate Spring managed Hibernate interceptors (http://docs.jboss.org/hibernate/orm/4.3/manual/en-US/html/ch14.html) in Spring Boot? I'm using Spring Data JPA and Spring Data REST and need an Hibernate interceptor to act on an…
56
votes
3 answers

How to enable LockModeType.PESSIMISTIC_WRITE when looking up entities with Spring Data JPA?

How can I achieve the equivalent of this code: tx.begin(); Widget w = em.find(Widget.class, 1L, LockModeType.PESSIMISTIC_WRITE); w.decrementBy(4); em.flush(); tx.commit(); ... but using Spring and Spring-Data-JPA annotations? The basis of my…
Greg Kopff
  • 15,945
  • 12
  • 55
  • 78
54
votes
4 answers

'not equals' condition when using Spring CrudRepository

How should I build my findBy method name so I can implement a where clause - statusCode != 'Denied' Is this be an option? findByStatusCodeNotIn(List statusCode); What if I want to just pass a String instead of a list? Thank You
Jay Kumo
  • 671
  • 1
  • 5
  • 9
54
votes
13 answers

Failed to auto-configure a DataSource: 'spring.datasource.url' is not specified

I have created a basic spring boot application from SPRING INITIALIZR with the Web, MongoDB and JPA dependencies. When I try to run the spring boot application I am getting the following exception: Error starting ApplicationContext. To display the…
Subash J
  • 2,028
  • 3
  • 13
  • 27
54
votes
4 answers

Dynamic spring data jpa repository query with arbitrary AND clauses

I'm using Spring data jpa repositories, Got a requirement to give search feature with different fields. Entering fields before search is optional.I have 5 fields say EmployeeNumber, Name, Married,Profession and DateOfBirth. Here i need to query only…
Mr.Chowdary
  • 3,389
  • 9
  • 42
  • 66
53
votes
3 answers

Spring Data JPA - Multiple EnableJpaRepositories

My application has multiple data sources , so i have created two data source configuration classes based on this URL . But while running the spring boot application am getting error Description: Field userDataRepo in…
Ansar Samad
  • 729
  • 2
  • 8
  • 15
53
votes
4 answers

Spring Boot: autowire beans from library project

I'm struggling to autowire beans from my custom library, imported with gradle. after reading couple of similar topics I am still unable to find solution. I have a Spring Boot project that depends on another project (my custom library with…
maret
  • 1,826
  • 1
  • 13
  • 18
53
votes
4 answers

Spring + hibernate versus Spring Data JPA: Are they different?

Although not novice, I am trying to learn spring framework (again!) in order to be sure that I really understand this. I have got fair idea on core Spring (DI). Now, I am focusing on Data layer. I have come across the term "Spring and Hibernate". As…
CuriousMind
  • 8,301
  • 22
  • 65
  • 134
53
votes
2 answers

How to test Spring's declarative caching support on Spring Data repositories?

I have developed a Spring Data repository, MemberRepository interface, that extends org.springframework.data.jpa.repository.JpaRepository. MemberRepository has a method: @Cacheable(CacheConfiguration.DATABASE_CACHE_NAME) Member findByEmail(String…
balteo
  • 23,602
  • 63
  • 219
  • 412
52
votes
6 answers

Spring-Data JPA CrudRepository returns Iterable, is it OK to cast this to List?

I'm writing a code-gen tool to generate backend wiring code for Spring Boot applications using Spring Data JPA and it's mildly annoying me that the methods in the CrudRepository return Iterable rather than List, as Iterable doesn't provide quite…
james_s_tayler
  • 1,823
  • 1
  • 15
  • 20
51
votes
8 answers

Spring JPA :: No converter found capable of converting from type

I am using spring with JPA and trying to execute the query using @query with SQL query and trying to map the result to an object. I have different entity classes and mapping to another DTO as I do not want all the columns. Getting below error No…
Anjali
  • 1,623
  • 5
  • 30
  • 50