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

Filtering database rows with spring-data-jpa and spring-mvc

I have a spring-mvc project that is using spring-data-jpa for data access. I have a domain object called Travel which I want to allow the end-user to apply a number of filters to it. For that, I've implemented the following…
Serafeim
  • 14,962
  • 14
  • 91
  • 133
69
votes
5 answers

Can't set JPA naming strategy after configuring multiple data sources (Spring 1.4.1 / Hibernate 5.x)

I am using Spring Boot 1.4.1 which uses Hibernate 5.0.11. Initially I configured a data source using application.properties like…
Uncle Long Hair
  • 2,719
  • 3
  • 23
  • 33
68
votes
2 answers

Spring Boot Data JPA - Modifying update query - Refresh persistence context

I'm working with Spring Boot 1.3.0.M4 and a MySQL database. I have a problem when using modifying queries, the EntityManager contains outdated entities after the query has executed. Original JPA Repository: public interface EmailRepository extends…
ciri-cuervo
  • 1,696
  • 2
  • 18
  • 21
67
votes
6 answers

JPQL Like Case Insensitive

I want to search data in User table by name case insensitive. @Repository public interface UserRepository extends JpaRepository { @Query("select u from User u where lower(u.name) like %lower(?1)%") public List
windupurnomo
  • 1,121
  • 1
  • 11
  • 22
66
votes
6 answers

How to set hibernate.format_sql in spring-boot?

I'm using spring-boot autoconfiguration for database injection, with properties defined: spring.jpa.database=POSTGRESQL spring.jpa.show-sql=true spring.jpa.hibernate.ddl-auto=update But how can I set the hibernate.format_sql=true? Is that not…
membersound
  • 81,582
  • 193
  • 585
  • 1,120
64
votes
4 answers

Spring Data JPA: query ManyToMany

I have entities User and Test @Entity public class User { private Long id; private String userName; } @Entity public class Test { private Long id; @ManyToMany private Set users; } I can get all tests by User…
qwe asd
  • 1,598
  • 3
  • 21
  • 31
63
votes
4 answers

Spring data jpa - How to combine multiple And and Or through method name

I am trying to migrate the application. I am working on from Hibernate to Spring Data Jpa. Though spring data jpa offers simple methods for query building, I am stuck up in creating query method that uses both And and Or operator. MethodName -…
Preethi Ramanujam
  • 631
  • 1
  • 5
  • 5
62
votes
5 answers

Spring Data JPA - "could not initialize proxy - no Session" - With Methods marked as transactional

I have a model that has a pretty large graph of sub entities and hibernate ends up making around 9 statements to lazily fetch all of the data needed but about 4 levels deep I get a "could not initialize proxy - no Session" error and I am not sure…
douglasrlee
  • 663
  • 1
  • 5
  • 7
61
votes
2 answers

What is the difference between an Spring Entity Manager and Spring Data Repository?

I am using JPA in a website. After exploring about options for saving data, I found 2 approach. The first approach is using an implementation of javax.persistence.EntityManager. I used LocalContainerEntityManagerFactoryBean to instantiate an…
zfranciscus
  • 16,175
  • 10
  • 47
  • 53
60
votes
3 answers

LocalDateTime to ZonedDateTime

I have Java 8 Spring web app that will support multiple regions. I need to make calendar events for a customer location. So let's say my web and Postgres server is hosted in MST timezone (but I guess it could be anywhere if we go cloud). But the…
sonoerin
  • 5,015
  • 23
  • 75
  • 132
60
votes
1 answer

Are you supposed to have one repository per table in JPA?

Are you supposed to have one repository per table in JPA? If not, how do you resolve the generics in the repository database? For example, below is a StoreRepository. It handles CRUD operations on the Store object. If I wanted the repository to save…
user1099123
  • 6,063
  • 5
  • 30
  • 35
60
votes
11 answers

EntityNotFoundException in Hibernate Many To One mapping however data exist

I am getting javax.persistence.EntityNotFoundException error when I am trying to get User through Invoice object invoice.getUser().getId() Error is as follows javax.persistence.EntityNotFoundException: Unable to find com.indianretailshop.domain.User…
Badal Singh
  • 918
  • 1
  • 6
  • 13
59
votes
6 answers

Spring Data JPA And NamedEntityGraphs

currently I am wrestling with being able to fetch only the data I need. The findAll() method needs to fetch data dependant on where its getting called. I do not want to end up writing different methods for each entity graph. Also, I would avoid…
dendimiiii
  • 1,659
  • 3
  • 15
  • 26
58
votes
4 answers

Spring Data JPA. How to get only a list of IDs from findAll() method

I have a very complicated model. Entity has a lot relationship and so on. I try to use Spring Data JPA and I prepared a repository. but when I invoke a method findAll() with specification for the object a have a performance issue because objects are…
tomasz-mer
  • 3,753
  • 10
  • 50
  • 69
58
votes
3 answers