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
46
votes
1 answer

SpringBoot JPA need no .save() on @Transactional?

I have short question: Do I need a repo.save(x) call on @Transactional methods? I ask cause I see changes on my DB without save, and read no clear docs about it. So is it working as intended, or just a (welcome) unexpected…
Gregor Sklorz
  • 1,645
  • 2
  • 19
  • 27
46
votes
8 answers

How to reset between tests

I have a test class @RunWith(SpringRunner.class) @DataJpaTest I have two tests. In every test I do the same operation, persist the object. Only the find call are different. If I run both tests together they fail but if I run test one after another…
robert trudel
  • 5,283
  • 17
  • 72
  • 124
46
votes
6 answers

Spring data : CrudRepository's save method and update

I wanted to know if the {save} method in CrudRepository do an update if it finds already the entry in the database like : @Repository public interface ProjectDAO extends CrudRepository {} @Service public class ProjectServiceImpl…
OddDev
  • 1,521
  • 7
  • 23
  • 45
46
votes
2 answers

Distinct results from Spring Data JPA Specification that uses join

I have the following Specification that I use to query for any Contact entities that are tied to certain ManagedApplication entities. I pass in a Collection that contains the ids of the ManagedApplication entities that I am searching for.…
Andrew Mairose
  • 10,615
  • 12
  • 60
  • 102
46
votes
8 answers

Spring data JPA and parameters that can be null

My understanding is, that with Spring data JPA I cannot have a query method to fetch all rows where a column equals a given non-null method parameter and use the same method to fetch all rows where this column is NULL when the method parameter is…
Sebastian S.
  • 1,545
  • 6
  • 24
  • 41
45
votes
2 answers

Page<> vs Slice<> when to use which?

I've read in Spring Jpa Data documentation about two different types of objects when you 'page' your dynamic queries made out of repositories. Page and Slice Page findByLastname(String lastname, Pageable pageable); Slice
Emil Hotkowski
  • 2,233
  • 1
  • 13
  • 19
45
votes
4 answers

Spring JpaRepository - Detach and Attach entity

I am using spring boot and hibernate over jpa. I am using JpaRepository interface to implement my repositories. As with following UserRepository public interface UserRepository extends JpaRepository { } I want to achieve following Load…
amique
  • 2,176
  • 7
  • 34
  • 53
45
votes
6 answers

Spring-Data-Jpa Repository - Underscore on Entity Column Name

I am using spring-data-jpa on a spring webmvc project. I am facing an issue using query creation on a Repository of one of my Entities. Below you can see my Entity, my Repository and the Exception. My Entity: @Entity @Table(schema =…
Georgios Syngouroglou
  • 18,813
  • 9
  • 90
  • 92
45
votes
13 answers

Autowiring fails: Not an managed Type

I have a big problem in my diploma project and would be very glad if you guys could help me! I made a Maven Multi Module Project and have 3 "Core-projects" NaviClean: (Parent) NaviCleanDomain: contains the domain model with all my entities and an…
alfred_m
  • 1,879
  • 3
  • 13
  • 10
44
votes
4 answers

Spring Data JPA Unable to locate Attribute with the given name

I was trying to use Spring Data JPA on Spring Boot and I kept getting error, I can't figure out what the problem is: Unable to locate Attribute with the the given name [firstName] on this ManagedType…
smned
  • 663
  • 1
  • 6
  • 19
44
votes
10 answers

Set default page size for JPA Pageable Object

I have a PagingandSorting Repository which has a method that accecpts a pageable object. I also have a controller that accepts a pageable object through the URL. My use case is that, if a user specifies a page size parameter in the URL i must take…
43
votes
3 answers

Possibly consider using a shorter maxLifetime value - hikari connection pool spring boot

After starting my SpringBoot application, getting an exception on few minutes of the server startup. Did not use any HikariPool Configuration externally, Spring Boot is using HikariPool by default This is the error I am getting in the…
Sanjog
  • 456
  • 1
  • 4
  • 6
43
votes
3 answers

Can Spring Boot application handle multiple requests simultaneously?

I am developing Rest APIs with Spring Boot which is deployed on AWS Beanstalk. Potentially, the service will be getting hits from thousands of clients every day. Therefore I would like to understand capability of Spring Boot of handling multiple…
ddd
  • 4,665
  • 14
  • 69
  • 125
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…
43
votes
6 answers

Spring nested transactions

In my Spring Boot project I have implemented following service method: @Transactional public boolean validateBoard(Board board) { boolean result = false; if (inProgress(board)) { if (!canPlayWithCurrentBoard(board)) { …
alexanoid
  • 24,051
  • 54
  • 210
  • 410