[JAVA-32833] (#16265)

* [JAVA-32833]

* [JAVA-32833] Fixed configuration
This commit is contained in:
panos-kakos 2024-04-08 23:54:14 +03:00 committed by GitHub
parent b5bfa4697d
commit c3939b1850
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
16 changed files with 25 additions and 22 deletions

View File

@ -32,7 +32,7 @@ public class PersistenceConfig {
public LocalContainerEntityManagerFactoryBean entityManagerFactory() { public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
final LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean(); final LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
em.setDataSource(dataSource()); em.setDataSource(dataSource());
em.setPackagesToScan("com.baeldung.jpa.simple.entity"); em.setPackagesToScan("com.baeldung.jpa.simple.model");
final HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter(); final HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
em.setJpaVendorAdapter(vendorAdapter); em.setJpaVendorAdapter(vendorAdapter);

View File

@ -1,4 +1,4 @@
package com.baeldung.jpa.simple.entity; package com.baeldung.jpa.simple.model;
import jakarta.persistence.Entity; import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue; import jakarta.persistence.GeneratedValue;

View File

@ -1,4 +1,4 @@
package com.baeldung.jpa.simple.entity; package com.baeldung.jpa.simple.model;
import java.io.Serializable; import java.io.Serializable;

View File

@ -1,4 +1,4 @@
package com.baeldung.jpa.simple.entity; package com.baeldung.jpa.simple.model;
import java.time.ZonedDateTime; import java.time.ZonedDateTime;

View File

@ -5,7 +5,7 @@ import java.util.List;
import org.springframework.data.repository.ListCrudRepository; import org.springframework.data.repository.ListCrudRepository;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
import com.baeldung.jpa.simple.entity.Book; import com.baeldung.jpa.simple.model.Book;
@Repository @Repository
public interface BookListRepository extends ListCrudRepository<Book, Long> { public interface BookListRepository extends ListCrudRepository<Book, Long> {

View File

@ -7,7 +7,7 @@ import org.springframework.data.repository.ListCrudRepository;
import org.springframework.data.repository.PagingAndSortingRepository; import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
import com.baeldung.jpa.simple.entity.Book; import com.baeldung.jpa.simple.model.Book;
@Repository @Repository
public interface BookPagingAndSortingRepository extends PagingAndSortingRepository<Book, Long>, ListCrudRepository<Book, Long> { public interface BookPagingAndSortingRepository extends PagingAndSortingRepository<Book, Long>, ListCrudRepository<Book, Long> {

View File

@ -4,7 +4,7 @@ import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query; import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param; import org.springframework.data.repository.query.Param;
import com.baeldung.jpa.simple.entity.Foo; import com.baeldung.jpa.simple.model.Foo;
public interface IFooDAO extends JpaRepository<Foo, Long> { public interface IFooDAO extends JpaRepository<Foo, Long> {

View File

@ -6,7 +6,7 @@ import java.util.List;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import com.baeldung.jpa.simple.entity.User; import com.baeldung.jpa.simple.model.User;
public interface UserRepository extends JpaRepository<User, Integer>, UserRepositoryCustom { public interface UserRepository extends JpaRepository<User, Integer>, UserRepositoryCustom {

View File

@ -5,7 +5,7 @@ import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.function.Predicate; import java.util.function.Predicate;
import com.baeldung.jpa.simple.entity.User; import com.baeldung.jpa.simple.model.User;
public interface UserRepositoryCustom { public interface UserRepositoryCustom {

View File

@ -7,7 +7,7 @@ import java.util.Set;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.stream.Stream; import java.util.stream.Stream;
import com.baeldung.jpa.simple.entity.User; import com.baeldung.jpa.simple.model.User;
import jakarta.persistence.EntityManager; import jakarta.persistence.EntityManager;
import jakarta.persistence.PersistenceContext; import jakarta.persistence.PersistenceContext;

View File

@ -3,7 +3,7 @@ package com.baeldung.jpa.simple.service;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import com.baeldung.jpa.simple.entity.Foo; import com.baeldung.jpa.simple.model.Foo;
import com.baeldung.jpa.simple.repository.IFooDAO; import com.baeldung.jpa.simple.repository.IFooDAO;
@Service @Service

View File

@ -1,6 +1,6 @@
package com.baeldung.jpa.simple.service; package com.baeldung.jpa.simple.service;
import com.baeldung.jpa.simple.entity.Foo; import com.baeldung.jpa.simple.model.Foo;
public interface IFooService { public interface IFooService {
Foo create(Foo foo); Foo create(Foo foo);

View File

@ -1,14 +1,15 @@
package com.baeldung.jpa.simple; package com.baeldung.jpa.simple;
import static org.junit.jupiter.api.Assertions.assertEquals;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
import com.baeldung.jpa.simple.entity.Book; import com.baeldung.jpa.simple.model.Book;
import com.baeldung.jpa.simple.repository.BookListRepository; import com.baeldung.jpa.simple.repository.BookListRepository;
@SpringBootTest(classes = JpaApplication.class) @SpringBootTest(classes = JpaApplication.class)
@ -25,6 +26,6 @@ class BookListRepositoryIntegrationTest {
bookListRepository.saveAll(Arrays.asList(book1, book2, book3)); bookListRepository.saveAll(Arrays.asList(book1, book2, book3));
List<Book> books = bookListRepository.findBooksByAuthor("John Doe"); List<Book> books = bookListRepository.findBooksByAuthor("John Doe");
Assertions.assertEquals(3, books.size()); assertEquals(3, books.size());
} }
} }

View File

@ -1,9 +1,11 @@
package com.baeldung.jpa.simple; package com.baeldung.jpa.simple;
import static org.junit.jupiter.api.Assertions.assertEquals;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
@ -11,7 +13,7 @@ import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort; import org.springframework.data.domain.Sort;
import com.baeldung.jpa.simple.entity.Book; import com.baeldung.jpa.simple.model.Book;
import com.baeldung.jpa.simple.repository.BookPagingAndSortingRepository; import com.baeldung.jpa.simple.repository.BookPagingAndSortingRepository;
@SpringBootTest @SpringBootTest
@ -29,8 +31,8 @@ class BookPagingAndSortingRepositoryIntegrationTest {
Pageable pageable = PageRequest.of(0, 2, Sort.by("title").descending()); Pageable pageable = PageRequest.of(0, 2, Sort.by("title").descending());
List<Book> books = bookPagingAndSortingRepository.findBooksByAuthor("John Miller", pageable); List<Book> books = bookPagingAndSortingRepository.findBooksByAuthor("John Miller", pageable);
Assertions.assertEquals(2, books.size()); assertEquals(2, books.size());
Assertions.assertEquals(book3.getId(), books.get(0).getId()); assertEquals(book3.getId(), books.get(0).getId());
Assertions.assertEquals(book2.getId(), books.get(1).getId()); assertEquals(book2.getId(), books.get(1).getId());
} }
} }

View File

@ -10,7 +10,7 @@ import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.context.junit4.SpringRunner;
import com.baeldung.jpa.simple.entity.Foo; import com.baeldung.jpa.simple.model.Foo;
import com.baeldung.jpa.simple.service.IFooService; import com.baeldung.jpa.simple.service.IFooService;
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)

View File

@ -14,7 +14,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.test.context.junit.jupiter.SpringExtension;
import com.baeldung.jpa.simple.entity.User; import com.baeldung.jpa.simple.model.User;
import com.baeldung.jpa.simple.repository.UserRepository; import com.baeldung.jpa.simple.repository.UserRepository;
@ExtendWith(SpringExtension.class) @ExtendWith(SpringExtension.class)