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
5
votes
0 answers

Insert row if query condition met JPA and spring

I think this question is similar to Data base pessimistic locks with Spring data JPA (Hibernate under the hood) but thought I would ask separately as not exactly the same. I have a multi threaded/node springboot application on top of a mariadb…
Sodved
  • 8,428
  • 2
  • 31
  • 43
5
votes
2 answers

Update entity if already exists or create using spring jpa

I am new to spring data jpa. I have a scenario where I have to create an entity if not exists or update based on non primary key name.Below is the code i wrote to create new entity,it is working fine,but if an already exists record ,its creating…
Rocky4Ever
  • 828
  • 3
  • 12
  • 35
5
votes
1 answer

How to sort on embedded entity's property using Pageable?

I'm having an entity embedded into another as shown below. The repository is created on the DepEntity. I am trying retrieve the DepEntity objects sorted on totalExp column in ExpEntity. I m making a GET call using Pageable and getting the…
Santosh M K
  • 87
  • 2
  • 8
5
votes
3 answers

Return page object from JPA query

I want to create JPA with pagination. I tried to implement this: @Override public Page findAll(Specification spec, Pageable pageable) { int pageNumber = pageable.getPageNumber(); int…
Peter Penzov
  • 1,126
  • 134
  • 430
  • 808
5
votes
4 answers

JPA Repository null in junit tests

I am trying to write a very basic test for my repository/service classes, but for reasons I cannot seem to figure out, my autowired repository is always null. Here is the Repo class public interface RuleRepository extends JpaRepository
j-money
  • 509
  • 2
  • 9
  • 32
5
votes
0 answers

EntityScan in library project breaks SpringBootApplication auto configuration

I'm trying to build a library with spring which will handle task management for other spring boot applications. My library includes services, repositories and entities. Library will use data source of parent project for entities. My target is using…
cbidici
  • 51
  • 3
5
votes
2 answers

Spring Boot JPA externalizing the schema name to property file

I have 2 schemas for my spring boot application, which I hardcode in the Entity class like this @Entity @Table(name"TABLE_NAME_1", schema="SCHEMA_NAME_1") public class EntityName1{ ... } @Entity @Table(name"TABLE_NAME_2",…
Swastik
  • 273
  • 3
  • 15
5
votes
5 answers

Configure LocaldateTime in Spring Rest API

I use Java 10 with latest Spring spring-boot-starter-parent 2.1.0.RELEASE POM configuration: org.springframework.boot spring-boot-starter-parent
user1285928
  • 1,328
  • 29
  • 98
  • 147
5
votes
1 answer

Spring-Data Jpa Inheritance: Keeping Entity Id's in Children Entity

I'm dealing with a couple of Entities with Tree like structures that were getting more complicated so I decided to create an abstract class for it so code was a bit more mainainable: @Entity @Inheritance(strategy =…
5
votes
1 answer

Select record with max value from each group with Query DSL

I have a score table where I have players scores, and I want select unique records for each player with the biggest score. Here is the table: id | player_id | score | ... 1 | 1 | 10 | ... 2 | 2 | 21 | ... 3 | 3 | 9 …
Denis Stephanov
  • 4,563
  • 24
  • 78
  • 174
5
votes
1 answer

Spock - mocked repository method save() giving NullPointerException

I'm using Spock to unit test a service in my app. Recently I encountered a weird behavior I don't really understand. Here is my unit test: def setup() { parkingSessionRepository = Mock(ParkingSessionRepository.class) parkingSessionMapper =…
5
votes
2 answers

Spring Data JPA Query by Example with access to nested Objects Attributes

I use Query by Example and want to know how I can find objects with certain properties in the nested objects. A plan anyone? Here is my example Code: ExampleMatcher matcher = ExampleMatcher.matching() …
Martin
  • 87
  • 1
  • 9
5
votes
3 answers

Spring data query dsl how to add order by?

I'm new to Querydsl, I'm working on Spring data and Querydsl to make a dynamic filter, I use the interface: QueryDslPredicateExecutor so I can filter data using different entity fields, now I want to add "order by" to my query based on a…
e2rabi
  • 4,728
  • 9
  • 42
  • 69
5
votes
0 answers

How to add entity listener to entity imported from library in SpringBoot

In SpringBoot project, I am using entities from third party libraries and I want to bind some entity listener (that I wrote) to it. However, I can't edit that entity and add @EntityListeners annotation to it, so is there any other way to bind my…
milosdju
  • 783
  • 12
  • 27
5
votes
1 answer

Spring data jpa sort by nested object collection size

I am using a spring boot application and there exists the following 2 entities. Person.java @Entity @Data @EqualsAndHashCode(callSuper = true) @AllArgsConstructor @NoArgsConstructor @Table(name = "PERSON") public class Person extends BaseEntity { …
Philip John
  • 5,275
  • 10
  • 43
  • 68