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
114
votes
9 answers

How does the FetchMode work in Spring Data JPA

I do have a relation between three model object in my project (model and repository snippets in the end of the post. When I call PlaceRepository.findById it does fire three select queries: ("sql") SELECT * FROM place p where id = arg SELECT * FROM…
SirKometa
  • 1,857
  • 3
  • 16
  • 26
114
votes
14 answers

spring data jpa @query and pageable

I'm using Spring Data JPA, and when I use @Query to to define a query WITHOUT Pageable, it works: public interface UrnMappingRepository extends JpaRepository { @Query(value = "select * from internal_uddi where urn like %?1% or…
Awakening
  • 3,615
  • 8
  • 35
  • 51
113
votes
8 answers

Lombok @Builder and JPA Default constructor

I'm using project Lombok together with Spring Data JPA. Is there any way to connect Lombok @Builder with JPA default constructor? Code: @Entity @Builder class Person { @Id @GeneratedValue(strategy = GenerationType.AUTO) private Long…
krzakov
  • 3,871
  • 11
  • 37
  • 52
109
votes
5 answers

POSTing a @OneToMany sub-resource association in Spring Data REST

Currently I have a Spring Boot application using Spring Data REST. I have a domain entity Post which has the @OneToMany relationship to another domain entity, Comment. These classes are structured as follows: Post.java: @Entity public class Post { …
ccampo
  • 1,483
  • 3
  • 12
  • 14
107
votes
14 answers

Delete Not Working with JpaRepository

I have a spring 4 app where I'm trying to delete an instance of an entity from my database. I have the following entity: @Entity public class Token implements Serializable { @Id @SequenceGenerator(name = "seqToken", sequenceName =…
userspaced
  • 1,273
  • 2
  • 10
  • 9
106
votes
6 answers

How to do bulk (multi row) inserts with JpaRepository?

When calling the saveAll method of my JpaRepository with a long List from the service layer, trace logging of Hibernate shows single SQL statements being issued per entity. Can I force it to do a bulk insert (i.e. multi-row) without needing…
Tobias Hermann
  • 9,936
  • 6
  • 61
  • 134
105
votes
5 answers

How to use @Transactional with Spring Data?

I just started working on a Spring-data, Hibernate, MySQL, JPA project. I switched to spring-data so that I wouldn't have to worry about creating queries by hand. I noticed that the use of @Transactional isn't required when you're using spring-data…
Byron Voorbach
  • 4,365
  • 5
  • 27
  • 35
101
votes
7 answers

Spring Data JPA findOne() change to Optional how to use this?

I'm learning SpringBoot2.0 with Java8. And I followed some blog-making tutorial example. The tutorial source code is: @GetMapping("/{id}/edit") public String edit(@PathVariable Long id, Model model) { model.addAttribute("categoryDto",…
Hulk Choi
  • 1,067
  • 2
  • 8
  • 12
101
votes
3 answers

Spring Data Rest - Sort by multiple properties

I have an entity as below Class Person{ String id; String name; String numberOfHands; } With Spring Data Rest (Gosling Release Train), I'm able to specify localhost/Person?sort=name,asc for sorting name name ascending. Now, in a case where I need…
rakpan
  • 2,773
  • 4
  • 26
  • 36
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
97
votes
2 answers

Understanding the Spring Data JPA @NoRepositoryBean interface

I encountered the @NoRepositoryBean interface several times whilst reading the Spring Data documentation. To quote from the documentation: If you're using automatic repository interface detection using the Spring namespace using the interface…
balteo
  • 23,602
  • 63
  • 219
  • 412
95
votes
4 answers

How to sort by multiple properties in Spring Data (JPA) derived queries?

I'm looking at the examples giving on this page (https://docs.spring.io/spring-data/jpa/docs/current/reference/html/#jpa.repositories) about method naming, is it possible to create a complex chain method name such…
PDStat
  • 5,513
  • 10
  • 51
  • 86
91
votes
7 answers

JPA: update only specific fields

Is there a way for updating only some fields of an entity object using the method save from Spring Data JPA? For example I have a JPA entity like this: @Entity public class User { @Id private Long id; @NotNull private String login; @Id …
Andrea
  • 15,900
  • 18
  • 65
  • 84
87
votes
3 answers

Joining two table entities in Spring Data JPA

I want to write a query like SELECT * FROM Release_date_type a LEFT JOIN cache_media b on a.id=b.id. I am new to Spring Data JPA. I don't know how to write entities for Join query. Here is an attempt: @Entity @Table(name =…
S Atah Ahmed Khan
  • 1,313
  • 3
  • 14
  • 22
85
votes
10 answers

No converter found capable of converting from type to type

I am getting the following stacktrace: org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type [referencedata.ABDeadlineType] to type [referencedata.DeadlineType] at…
Menelaos
  • 23,508
  • 18
  • 90
  • 155