Merge pull request #6871 from eugenp/fix-spring-data-jpa
Fix spring data jpa
This commit is contained in:
@@ -89,5 +89,9 @@
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<properties>
|
||||
<start-class>com.baeldung.boot.Application</start-class>
|
||||
</properties>
|
||||
|
||||
</project>
|
||||
+3
-2
@@ -1,10 +1,11 @@
|
||||
package com.baeldung;
|
||||
package com.baeldung.boot;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
|
||||
|
||||
import com.baeldung.dao.repositories.impl.ExtendedRepositoryImpl;
|
||||
import com.baeldung.boot.daos.impl.ExtendedRepositoryImpl;
|
||||
import com.baeldung.multipledb.MultipleDbApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
@EnableJpaRepositories(repositoryBaseClass = ExtendedRepositoryImpl.class)
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
package com.baeldung.boot.config;
|
||||
|
||||
import com.baeldung.boot.services.IBarService;
|
||||
import com.baeldung.boot.services.impl.BarSpringDataJpaService;
|
||||
import org.springframework.context.annotation.*;
|
||||
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
|
||||
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
|
||||
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
||||
|
||||
@Configuration
|
||||
@Profile("!tc")
|
||||
@EnableTransactionManagement
|
||||
@EnableJpaAuditing
|
||||
public class PersistenceConfiguration {
|
||||
|
||||
@Bean
|
||||
public IBarService barSpringDataJpaService() {
|
||||
return new BarSpringDataJpaService();
|
||||
}
|
||||
|
||||
}
|
||||
+3
-2
@@ -1,10 +1,11 @@
|
||||
package com.baeldung.dao.repositories;
|
||||
package com.baeldung.boot.daos;
|
||||
|
||||
import com.baeldung.domain.Article;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
|
||||
import com.baeldung.boot.domain.Article;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
+2
-2
@@ -1,8 +1,8 @@
|
||||
package com.baeldung.dao.repositories;
|
||||
package com.baeldung.boot.daos;
|
||||
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import com.baeldung.domain.Item;
|
||||
import com.baeldung.boot.domain.Item;
|
||||
|
||||
@Repository
|
||||
public interface CustomItemRepository {
|
||||
+2
-2
@@ -1,8 +1,8 @@
|
||||
package com.baeldung.dao.repositories;
|
||||
package com.baeldung.boot.daos;
|
||||
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import com.baeldung.domain.ItemType;
|
||||
import com.baeldung.boot.domain.ItemType;
|
||||
|
||||
@Repository
|
||||
public interface CustomItemTypeRepository {
|
||||
+2
-2
@@ -1,8 +1,8 @@
|
||||
package com.baeldung.batchinserts.repository;
|
||||
package com.baeldung.boot.daos;
|
||||
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
|
||||
import com.baeldung.batchinserts.model.Customer;
|
||||
import com.baeldung.boot.domain.Customer;
|
||||
|
||||
/**
|
||||
* JPA CrudRepository interface
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.baeldung.dao.repositories;
|
||||
package com.baeldung.boot.daos;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
package com.baeldung.dao.repositories;
|
||||
package com.baeldung.boot.daos;
|
||||
|
||||
import com.baeldung.domain.Student;
|
||||
import com.baeldung.boot.domain.Student;
|
||||
|
||||
public interface ExtendedStudentRepository extends ExtendedRepository<Student, Long> {
|
||||
}
|
||||
+3
-2
@@ -1,8 +1,9 @@
|
||||
package com.baeldung.dao.repositories;
|
||||
package com.baeldung.boot.daos;
|
||||
|
||||
import com.baeldung.domain.Bar;
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
|
||||
import com.baeldung.boot.domain.Bar;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public interface IBarCrudRepository extends CrudRepository<Bar, Serializable> {
|
||||
+3
-2
@@ -1,10 +1,11 @@
|
||||
package com.baeldung.dao;
|
||||
package com.baeldung.boot.daos;
|
||||
|
||||
import com.baeldung.domain.Foo;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
|
||||
import com.baeldung.boot.domain.Foo;
|
||||
|
||||
public interface IFooDao extends JpaRepository<Foo, Long> {
|
||||
|
||||
@Query("SELECT f FROM Foo f WHERE LOWER(f.name) = LOWER(:name)")
|
||||
+3
-2
@@ -1,7 +1,8 @@
|
||||
package com.baeldung.dao.repositories;
|
||||
package com.baeldung.boot.daos;
|
||||
|
||||
import com.baeldung.domain.MerchandiseEntity;
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
|
||||
import com.baeldung.boot.domain.MerchandiseEntity;
|
||||
|
||||
public interface InventoryRepository extends CrudRepository<MerchandiseEntity, Long> {
|
||||
}
|
||||
+2
-2
@@ -1,9 +1,9 @@
|
||||
package com.baeldung.dao.repositories;
|
||||
package com.baeldung.boot.daos;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import com.baeldung.domain.ItemType;
|
||||
import com.baeldung.boot.domain.ItemType;
|
||||
|
||||
@Repository
|
||||
public interface ItemTypeRepository extends JpaRepository<ItemType, Long>, CustomItemTypeRepository, CustomItemRepository {
|
||||
+2
-2
@@ -1,9 +1,9 @@
|
||||
package com.baeldung.dao.repositories;
|
||||
package com.baeldung.boot.daos;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import com.baeldung.domain.Location;
|
||||
import com.baeldung.boot.domain.Location;
|
||||
|
||||
@Repository
|
||||
public interface LocationRepository extends JpaRepository<Location, Long> {
|
||||
+2
-2
@@ -1,10 +1,10 @@
|
||||
package com.baeldung.dao.repositories;
|
||||
package com.baeldung.boot.daos;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import org.springframework.data.repository.Repository;
|
||||
|
||||
import com.baeldung.domain.Location;
|
||||
import com.baeldung.boot.domain.Location;
|
||||
|
||||
@org.springframework.stereotype.Repository
|
||||
public interface ReadOnlyLocationRepository extends Repository<Location, Long> {
|
||||
+2
-2
@@ -1,11 +1,11 @@
|
||||
package com.baeldung.dao.repositories;
|
||||
package com.baeldung.boot.daos;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import com.baeldung.domain.Store;
|
||||
import com.baeldung.boot.domain.Store;
|
||||
|
||||
@Repository
|
||||
public interface StoreRepository extends JpaRepository<Store, Long> {
|
||||
+3
-3
@@ -1,12 +1,12 @@
|
||||
package com.baeldung.dao.repositories.impl;
|
||||
package com.baeldung.boot.daos.impl;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import com.baeldung.dao.repositories.CustomItemRepository;
|
||||
import com.baeldung.domain.Item;
|
||||
import com.baeldung.boot.daos.CustomItemRepository;
|
||||
import com.baeldung.boot.domain.Item;
|
||||
|
||||
@Repository
|
||||
public class CustomItemRepositoryImpl implements CustomItemRepository {
|
||||
+3
-3
@@ -1,4 +1,4 @@
|
||||
package com.baeldung.dao.repositories.impl;
|
||||
package com.baeldung.boot.daos.impl;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
|
||||
@@ -7,8 +7,8 @@ import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import com.baeldung.domain.ItemType;
|
||||
import com.baeldung.dao.repositories.CustomItemTypeRepository;
|
||||
import com.baeldung.boot.daos.CustomItemTypeRepository;
|
||||
import com.baeldung.boot.domain.ItemType;
|
||||
|
||||
@Repository
|
||||
public class CustomItemTypeRepositoryImpl implements CustomItemTypeRepository {
|
||||
+3
-2
@@ -1,4 +1,4 @@
|
||||
package com.baeldung.dao.repositories.impl;
|
||||
package com.baeldung.boot.daos.impl;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
@@ -10,10 +10,11 @@ import javax.persistence.criteria.CriteriaQuery;
|
||||
import javax.persistence.criteria.Root;
|
||||
import javax.transaction.Transactional;
|
||||
|
||||
import com.baeldung.dao.repositories.ExtendedRepository;
|
||||
import org.springframework.data.jpa.repository.support.JpaEntityInformation;
|
||||
import org.springframework.data.jpa.repository.support.SimpleJpaRepository;
|
||||
|
||||
import com.baeldung.boot.daos.ExtendedRepository;
|
||||
|
||||
public class ExtendedRepositoryImpl<T, ID extends Serializable> extends SimpleJpaRepository<T, ID> implements ExtendedRepository<T, ID> {
|
||||
|
||||
private EntityManager entityManager;
|
||||
+3
-2
@@ -1,8 +1,9 @@
|
||||
package com.baeldung.dao.repositories.impl;
|
||||
package com.baeldung.boot.daos.impl;
|
||||
|
||||
import com.baeldung.domain.Person;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import com.baeldung.boot.domain.Person;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.PersistenceContext;
|
||||
import javax.transaction.Transactional;
|
||||
+3
-2
@@ -1,8 +1,9 @@
|
||||
package com.baeldung.dao.repositories.user;
|
||||
package com.baeldung.boot.daos.user;
|
||||
|
||||
import com.baeldung.domain.user.Possession;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
import com.baeldung.boot.domain.Possession;
|
||||
|
||||
public interface PossessionRepository extends JpaRepository<Possession, Long> {
|
||||
|
||||
}
|
||||
+12
-12
@@ -1,6 +1,5 @@
|
||||
package com.baeldung.dao.repositories.user;
|
||||
package com.baeldung.boot.daos.user;
|
||||
|
||||
import com.baeldung.domain.user.User;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.domain.Sort;
|
||||
@@ -9,6 +8,8 @@ import org.springframework.data.jpa.repository.Modifying;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
|
||||
import com.baeldung.boot.domain.User;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
@@ -18,11 +19,11 @@ public interface UserRepository extends JpaRepository<User, Integer> , UserRepos
|
||||
|
||||
Stream<User> findAllByName(String name);
|
||||
|
||||
@Query("select u from User u where u.email like '%@gmail.com'")
|
||||
List<User> findUsersWithGmailAddress();
|
||||
|
||||
@Query("SELECT u FROM User u WHERE u.status = 1")
|
||||
Collection<User> findAllActiveUsers();
|
||||
|
||||
@Query("select u from User u where u.email like '%@gmail.com'")
|
||||
List<User> findUsersWithGmailAddress();
|
||||
|
||||
@Query(value = "SELECT * FROM Users u WHERE u.status = 1", nativeQuery = true)
|
||||
Collection<User> findAllActiveUsersNative();
|
||||
@@ -74,14 +75,14 @@ public interface UserRepository extends JpaRepository<User, Integer> , UserRepos
|
||||
@Query(value = "INSERT INTO Users (name, age, email, status, active) VALUES (:name, :age, :email, :status, :active)", nativeQuery = true)
|
||||
@Modifying
|
||||
void insertUser(@Param("name") String name, @Param("age") Integer age, @Param("email") String email, @Param("status") Integer status, @Param("active") boolean active);
|
||||
|
||||
|
||||
@Modifying
|
||||
@Query(value = "UPDATE Users u SET status = ? WHERE u.name = ?", nativeQuery = true)
|
||||
int updateUserSetStatusForNameNativePostgres(Integer status, String name);
|
||||
|
||||
|
||||
@Query(value = "SELECT u FROM User u WHERE u.name IN :names")
|
||||
List<User> findUserByNameList(@Param("names") Collection<String> names);
|
||||
|
||||
List<User> findUserByNameList(@Param("names") Collection<String> names);
|
||||
|
||||
void deleteAllByCreationDateAfter(LocalDate date);
|
||||
|
||||
@Modifying(clearAutomatically = true, flushAutomatically = true)
|
||||
@@ -89,11 +90,10 @@ public interface UserRepository extends JpaRepository<User, Integer> , UserRepos
|
||||
void deactivateUsersNotLoggedInSince(@Param("date") LocalDate date);
|
||||
|
||||
@Modifying(clearAutomatically = true, flushAutomatically = true)
|
||||
@Query("delete from User u where u.active = false")
|
||||
@Query("delete User u where u.active = false")
|
||||
int deleteDeactivatedUsers();
|
||||
|
||||
@Modifying(clearAutomatically = true, flushAutomatically = true)
|
||||
@Query(value = "alter table Users add column deleted int(1) not null default 0", nativeQuery = true)
|
||||
@Query(value = "alter table USERS.USERS add column deleted int(1) not null default 0", nativeQuery = true)
|
||||
void addDeletedColumn();
|
||||
|
||||
}
|
||||
+3
-3
@@ -1,14 +1,14 @@
|
||||
package com.baeldung.dao.repositories.user;
|
||||
package com.baeldung.boot.daos.user;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
import com.baeldung.domain.user.User;
|
||||
import com.baeldung.boot.domain.User;
|
||||
|
||||
public interface UserRepositoryCustom {
|
||||
List<User> findUserByEmails(Set<String> emails);
|
||||
|
||||
|
||||
List<User> findAllUsersByPredicates(Collection<Predicate<User>> predicates);
|
||||
}
|
||||
+3
-3
@@ -1,4 +1,4 @@
|
||||
package com.baeldung.dao.repositories.user;
|
||||
package com.baeldung.boot.daos.user;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
@@ -15,7 +15,7 @@ import javax.persistence.criteria.Path;
|
||||
import javax.persistence.criteria.Predicate;
|
||||
import javax.persistence.criteria.Root;
|
||||
|
||||
import com.baeldung.domain.user.User;
|
||||
import com.baeldung.boot.domain.User;
|
||||
|
||||
public class UserRepositoryCustomImpl implements UserRepositoryCustom {
|
||||
|
||||
@@ -42,7 +42,7 @@ public class UserRepositoryCustomImpl implements UserRepositoryCustom {
|
||||
return entityManager.createQuery(query)
|
||||
.getResultList();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public List<User> findAllUsersByPredicates(Collection<java.util.function.Predicate<User>> predicates) {
|
||||
List<User> allUsers = entityManager.createQuery("select u from User u", User.class).getResultList();
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package com.baeldung.ddd.event;
|
||||
package com.baeldung.boot.ddd.event;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package com.baeldung.ddd.event;
|
||||
package com.baeldung.boot.ddd.event;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package com.baeldung.ddd.event;
|
||||
package com.baeldung.boot.ddd.event;
|
||||
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package com.baeldung.ddd.event;
|
||||
package com.baeldung.boot.ddd.event;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package com.baeldung.ddd.event;
|
||||
package com.baeldung.boot.ddd.event;
|
||||
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package com.baeldung.ddd.event;
|
||||
package com.baeldung.boot.ddd.event;
|
||||
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user