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
78
votes
7 answers

Spring Data optional parameter in query method

I want to write some query methods in repository layer. This method must ignore null parameters. For example: List findByBarAndGoo(Bar barParam, @optional Goo gooParam); This method must be return Foo by this condition: bar == barParam && goo…
mohammad_1m2
  • 1,571
  • 5
  • 19
  • 38
77
votes
9 answers

Handling soft-deletes with Spring JPA

I have a table Stuff defined as... id, ..., active Active is the soft-delete flag and is always 1 or 0. Long term this may go away in favor of a historical table. public interface StuffRepository extends JpaRepository {}…
Andrew White
  • 52,720
  • 19
  • 113
  • 137
77
votes
5 answers

Spring Data JPA Update @Query not updating?

I have an update query: @Modifying @Transactional @Query("UPDATE Admin SET firstname = :firstname, lastname = :lastname, login = :login, superAdmin = :superAdmin, preferenceAdmin = :preferenceAdmin, address = :address, zipCode = :zipCode, city =…
Stephane
  • 11,836
  • 25
  • 112
  • 175
76
votes
14 answers

Spring Data - ignore parameter if it has a null value

I want to have a spring data repository interface that takes two parameters. Is there a way to make it have the following behaviour? MyObject findByParameterOneAndParameterTwo( String parameterOne, String parameterTwo); If both parameters have a…
Panos
  • 7,227
  • 13
  • 60
  • 95
74
votes
8 answers

Pagination in Spring Data JPA (limit and offset)

I want the user to be able to specify the limit (the size of the amount returned) and offset (the first record returned / index returned) in my query method. Here are my classes without any paging capabilities. My entity: @Entity public Employee { …
chinesewhiteboi
  • 1,045
  • 1
  • 10
  • 10
74
votes
2 answers

What RuntimeException can Spring CrudRepository throw?

I have this Spring Data CrudRepository which handles the CRUD operations on a DB. @Repository public interface IUserRepository extends CrudRepository { } User is the Entity of a User table of my DB. CrudRepository adds namely the…
gvdm
  • 3,006
  • 5
  • 35
  • 73
73
votes
7 answers

How to convert a list of enity object to page object in Spring MVC (JPA)?

I have a List of entities. How do I convert it to Page Object using Spring MVC 4 and Spring Data JPA?
briantaurostack7
  • 1,193
  • 2
  • 14
  • 36
72
votes
8 answers

How to beautifully update a JPA entity in Spring Data?

So I have looked at various tutorials about JPA with Spring Data and this has been done different on many occasions and I am no quite sure what the correct approach is. Assume there is the follwing entity: package stackoverflowTest.dao; import…
Lukas Makor
  • 1,947
  • 2
  • 17
  • 24
72
votes
4 answers

How to generate a ddl creation script with a modern Spring Boot + Data JPA and Hibernate setup?

Currently, I'm using the default @SpringBootApplication annotation with the following properties in…
Casey
  • 6,166
  • 3
  • 35
  • 42
71
votes
2 answers

Why use returned instance after save() on Spring Data JPA Repository?

Here is the code: @Repository public interface AccountRepository extends JpaRepository {} JpaRepository from Spring Data JPA project. Here is the testing code: public class JpaAccountRepositoryTest extends JpaRepositoryTest { …
Aliaksandr Kazlou
  • 3,221
  • 6
  • 28
  • 34
71
votes
3 answers

Update single field using spring data jpa

I'm using spring-data's repositories - very convenient thing but I faced an issue. I easily can update whole entity but I believe it's pointless when I need to update only a single field: @Entity @Table(schema = "processors", name =…
Dmitrii Borovoi
  • 2,814
  • 9
  • 32
  • 50
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
68
votes
4 answers

PageRequest constructors have been deprecated

I'm working the Spring Data Commons v2+ snapshot, and I see that the constructors for a PageRequest have been deprecated. This appears to have occurred between M1 & M2. Unfortunately, this is the only [real] implementation of the Pageable…
end-user
  • 2,845
  • 6
  • 30
  • 56
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
65
votes
4 answers

Order By Date ASC with Spring Data

I try to make an application with Spring-Data-JPA on a table in order by ASC but it gives me an error: Invalid derived query! No property asc found for type java.util.Calendar Why ? List findAllOrderByDateAsc(); or @Query("SELECT * FROM foo…
MaximeF
  • 4,913
  • 4
  • 37
  • 51