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
84
votes
8 answers

Entity Class name is transformed into SQL table name with underscores

I have the following entity defined: @Entity @Table(name = "EmailTemplate") public class EmailTemplate { Despite the table annotation, I receive java.sql.SQLException: Invalid object name 'email_template'. How can I prevent an entity class such as…
James
  • 2,876
  • 18
  • 72
  • 116
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
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
79
votes
4 answers

why do we have to use @Modifying annotation for queries in Data Jpa

for example I have a method in my CRUD interface which deletes a user from the database: public interface CrudUserRepository extends JpaRepository { @Transactional @Modifying @Query("DELETE FROM User u WHERE u.id=:id") …
Artyom Emelyanenko
  • 1,323
  • 1
  • 11
  • 16
78
votes
1 answer

Technical differences between Spring Data JPA's findFirst and findTop

I recently started working with Spring data jpa. It would be highly appreciable if somebody could throw some light on the technical differences between Spring Data JPA's findFirst and findTop. Differences, usages. Thanks
Abdullah Khan
  • 12,010
  • 6
  • 65
  • 78
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
73
votes
7 answers

How to query data out of the box using Spring data JPA by both Sort and Pageable?

I am trying Spring data JPA in my project. I want to know if there is an out-of-the-box API to query data, by both Sort and Pageable. Of course, I know I can write that method myself, I just want to know if there is an out-of-the-box one. My DAO…
Tom
  • 2,857
  • 9
  • 46
  • 59
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
71
votes
9 answers

Spring boot JPA insert in TABLE with uppercase name with Hibernate

i have a table entity mapped as : @Entity public class ItemsToRegister implements Serializable{ @Id @Column(name = "ID_ITEM_TO_REGISTER") @GeneratedValue(strategy = GenerationType.AUTO) private int id; ..... When i try to insert new record in…
carlj
  • 896
  • 1
  • 6
  • 14
70
votes
5 answers

Refresh and fetch an entity after save (JPA/Spring Data/Hibernate)

I've these two simple entities Something and Property. The Something entity has a many-to-one relationship to Property, so when I create a new Something row, I assign an existing Property. Something: @Entity @Table(name = "something") public class…
Andrea Bevilacqua
  • 1,197
  • 3
  • 15
  • 27