diff --git a/persistence-modules/spring-data-jpa-2/README.md b/persistence-modules/spring-data-jpa-2/README.md index b2381b0720..4eccabe4d8 100644 --- a/persistence-modules/spring-data-jpa-2/README.md +++ b/persistence-modules/spring-data-jpa-2/README.md @@ -10,6 +10,5 @@ - [Spring Data JPA Delete and Relationships](https://www.baeldung.com/spring-data-jpa-delete) - [Spring Data JPA and Named Entity Graphs](https://www.baeldung.com/spring-data-jpa-named-entity-graphs) -- [Difference Between save() and saveAndFlush() in Spring Data JPA](https://www.baeldung.com/spring-data-jpa-save-saveandflush) - [Derived Query Methods in Spring Data JPA Repositories](https://www.baeldung.com/spring-data-derived-queries) - [LIKE Queries in Spring JPA Repositories](https://www.baeldung.com/spring-jpa-like-queries) diff --git a/persistence-modules/spring-data-jpa-3/README.md b/persistence-modules/spring-data-jpa-3/README.md index 07b529891d..bac52bf114 100644 --- a/persistence-modules/spring-data-jpa-3/README.md +++ b/persistence-modules/spring-data-jpa-3/README.md @@ -8,6 +8,7 @@ - [Spring Data JPA @Modifying Annotation](https://www.baeldung.com/spring-data-jpa-modifying-annotation) - [Spring Data JPA Batch Inserts](https://www.baeldung.com/spring-data-jpa-batch-inserts) - [Batch Insert/Update with Hibernate/JPA](https://www.baeldung.com/jpa-hibernate-batch-insert-update) +- [Difference Between save() and saveAndFlush() in Spring Data JPA](https://www.baeldung.com/spring-data-jpa-save-saveandflush) ### Eclipse Config After importing the project into Eclipse, you may see the following error: diff --git a/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/entity/Employee.java b/persistence-modules/spring-data-jpa-3/src/main/java/com/baeldung/entity/Employee.java similarity index 93% rename from persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/entity/Employee.java rename to persistence-modules/spring-data-jpa-3/src/main/java/com/baeldung/entity/Employee.java index 135439863f..4c3dbd25b7 100644 --- a/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/entity/Employee.java +++ b/persistence-modules/spring-data-jpa-3/src/main/java/com/baeldung/entity/Employee.java @@ -1,36 +1,36 @@ -package com.baeldung.entity; - -import javax.persistence.Entity; -import javax.persistence.Id; - -@Entity -public class Employee { - - @Id - private Long id; - private String name; - - public Employee() { - } - - public Employee(Long id, String name) { - this.id = id; - this.name = name; - } - - public Long getId() { - return id; - } - - public void setId(Long id) { - this.id = id; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } -} +package com.baeldung.entity; + +import javax.persistence.Entity; +import javax.persistence.Id; + +@Entity +public class Employee { + + @Id + private Long id; + private String name; + + public Employee() { + } + + public Employee(Long id, String name) { + this.id = id; + this.name = name; + } + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } +} diff --git a/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/repository/EmployeeRepository.java b/persistence-modules/spring-data-jpa-3/src/main/java/com/baeldung/repository/EmployeeRepository.java similarity index 95% rename from persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/repository/EmployeeRepository.java rename to persistence-modules/spring-data-jpa-3/src/main/java/com/baeldung/repository/EmployeeRepository.java index 2c4fee80e0..8f0a80814b 100644 --- a/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/repository/EmployeeRepository.java +++ b/persistence-modules/spring-data-jpa-3/src/main/java/com/baeldung/repository/EmployeeRepository.java @@ -1,9 +1,9 @@ -package com.baeldung.repository; - -import org.springframework.data.jpa.repository.JpaRepository; - -import com.baeldung.entity.Employee; - -public interface EmployeeRepository extends JpaRepository { - -} +package com.baeldung.repository; + +import org.springframework.data.jpa.repository.JpaRepository; + +import com.baeldung.entity.Employee; + +public interface EmployeeRepository extends JpaRepository { + +} diff --git a/persistence-modules/spring-data-jpa-2/src/test/java/com/baeldung/repository/EmployeeRepositoryIntegrationTest.java b/persistence-modules/spring-data-jpa-3/src/test/java/com/baeldung/repository/EmployeeRepositoryIntegrationTest.java similarity index 89% rename from persistence-modules/spring-data-jpa-2/src/test/java/com/baeldung/repository/EmployeeRepositoryIntegrationTest.java rename to persistence-modules/spring-data-jpa-3/src/test/java/com/baeldung/repository/EmployeeRepositoryIntegrationTest.java index ebeed276c9..0fc9918701 100644 --- a/persistence-modules/spring-data-jpa-2/src/test/java/com/baeldung/repository/EmployeeRepositoryIntegrationTest.java +++ b/persistence-modules/spring-data-jpa-3/src/test/java/com/baeldung/repository/EmployeeRepositoryIntegrationTest.java @@ -5,13 +5,14 @@ import static org.assertj.core.api.AssertionsForClassTypes.assertThat; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; +import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringRunner; +import com.baeldung.boot.Application; import com.baeldung.entity.Employee; @RunWith(SpringRunner.class) -@DataJpaTest +@SpringBootTest(classes = Application.class) public class EmployeeRepositoryIntegrationTest { private static final Employee EMPLOYEE1 = new Employee(1L, "John"); @@ -25,7 +26,7 @@ public class EmployeeRepositoryIntegrationTest { employeeRepository.save(EMPLOYEE1); assertEmployeePersisted(EMPLOYEE1); } - + @Test public void givenEmployeeEntity_whenInsertWithSaveAndFlush_ThenEmployeeIsPersisted() { employeeRepository.saveAndFlush(EMPLOYEE2);