Questions tagged [spring-data]

Spring Data is an umbrella open source project which contains many subprojects that are specific to a given database. The projects are developed by working together with many of the companies and community that are behind these exciting technologies.

The primary goal of the Spring Data project is to make it easier to build Spring-powered applications that use new data access technologies such as non-relational databases, map-reduce frameworks, and cloud based data services as well as provide improved support for relational database technologies.

This is an umbrella project which contains many subprojects that are specific to a given database. The projects are developed by working together with many of the companies and developers that are behind these exciting technologies.

Resources

Spring Data modules and specific tags

Noteworthy Questions and Answers

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

11873 questions
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
13 answers

Table 'DBNAME.hibernate_sequence' doesn't exist

I have a SpringBoot 2.0.1.RELEASE application using spring data / jpa org.springframework.boot spring-boot-starter-data-jpa But when I do an update in the Amazon Aurora…
en Peris
  • 1,537
  • 12
  • 31
  • 63
106
votes
17 answers

Conversion of List to Page in Spring

I am trying to convert list to page in spring. I have converted it using new PageImpl(users, pageable, users.size()); But now I having problem with sorting and pagination itself. When I try passing size and page, the pagination doesn't…
user3127109
  • 3,421
  • 8
  • 24
  • 33
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
102
votes
34 answers

Failed to start bean 'documentationPluginsBootstrapper' in spring data rest

I am using spring data rest for my application. I am getting following error and application doesn't get started when I add this method in repository:- Method:- @Modifying @Transactional @Query("from employee as ft where ft.company.id = ?1") void…
Galet
  • 5,853
  • 21
  • 82
  • 148
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
97
votes
4 answers

When to use @RestController vs @RepositoryRestResource

I have been looking at various examples of how to use Spring with REST. Our end target is a Spring HATEOAS/HAL setup I have seen two distinct methods for rendering REST within Spring Via @RestController within a Controller Via…
code
  • 4,073
  • 3
  • 27
  • 47
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
9 answers

Spring Data JPA and Exists query

I'm using Spring Data JPA (with Hibernate as my JPA provider) and want to define an exists method with a HQL query attached: public interface MyEntityRepository extends CrudRepository { @Query("select count(e) from MyEntity e…
Stefan Haberl
  • 9,812
  • 7
  • 72
  • 81
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
85
votes
1 answer

Spring Boot & Spring Data: how are Hibernate Sessions managed?

I am currently working on an application that uses Spring Boot and Spring Data (its JpaRepository interfaces to be precise) together with Hibernate. One thing I love about Hiberante is its caching feature - when you submit multiple queries that…
Martin Häusler
  • 6,544
  • 8
  • 39
  • 66
84
votes
2 answers

Query by Boolean properties in spring-data-jpa without using method parameters

Is it possible to query by Boolean properties in Spring Data JPA without using method parameters? Basically I would like this to work without using custom @Query annotation: @Query("SELECT c FROM Entity c WHERE c.enabled = true") public…
Mike Minicki
  • 8,216
  • 11
  • 39
  • 43
83
votes
3 answers

How to manually force a commit in a @Transactional method?

I'm using Spring / Spring-data-JPA and find myself needing to manually force a commit in a unit test. My use case is that I am doing a multi-threaded test in which I have to use data that is persisted before the threads are spawned. Unfortunately,…
Eric B.
  • 23,425
  • 50
  • 169
  • 316
82
votes
9 answers

Spring data jpa- No bean named 'entityManagerFactory' is defined; Injection of autowired dependencies failed

I'm developing application using spring data jpa,hibernate,mysql,tomcat7,maven and it's create error.I'm trying to figure it out but i failed. error are Cannot resolve reference to bean 'entityManagerFactory' while setting constructor argument;…
Ferdous Wahid
  • 3,227
  • 5
  • 27
  • 28
81
votes
13 answers

How to map Page to Page in spring-data-rest

When I hit the database with PagingAndSortingRepository.findAll(Pageable) I get Page. However, I want to expose DTO's to the client and not entities. I can create DTO just by injecting entity into it's constructor, but how do I map the…
Tuomas Toivonen
  • 21,690
  • 47
  • 129
  • 225