Spring JPA: spring-data-envers does not work yet with QueryDSL
authorGustavo Martin Morcuende <gu.martinm@gmail.com>
Tue, 26 Jul 2016 17:28:25 +0000 (19:28 +0200)
committerGustavo Martin Morcuende <gu.martinm@gmail.com>
Tue, 26 Jul 2016 17:28:25 +0000 (19:28 +0200)
See: https://github.com/spring-projects/spring-data-envers/pull/45

SpringJava/JPA/spring-jpa-persistence/src/main/java/de/spring/example/persistence/repository/AdDescriptionRepository.java
SpringJava/JPA/spring-jpa-persistence/src/main/java/de/spring/example/persistence/repository/AdRepository.java
SpringJava/JPA/spring-jpa-persistence/src/main/resources/spring-configuration/jpa-configuration.xml
SpringJava/JPA/spring-jpa-services/src/main/java/de/spring/example/services/impl/AdDescriptionServiceImpl.java

index 4b4e6fc..817884c 100644 (file)
@@ -2,8 +2,8 @@ package de.spring.example.persistence.repository;
 
 import org.springframework.data.domain.Page;
 import org.springframework.data.domain.Pageable;
-import org.springframework.data.querydsl.QueryDslPredicateExecutor;
 import org.springframework.data.repository.PagingAndSortingRepository;
+import org.springframework.data.repository.history.RevisionRepository;
 
 import de.spring.example.persistence.domain.Ad;
 import de.spring.example.persistence.domain.AdDescription;
@@ -15,7 +15,10 @@ import de.spring.example.persistence.domain.AdDescription;
  * Be careful with <code>@Transactional</code>. SimpleJpaRepository has annotated methods.
  *
  */
-public interface AdDescriptionRepository extends PagingAndSortingRepository<AdDescription, Long>, QueryDslPredicateExecutor<AdDescription> {
+public interface AdDescriptionRepository extends
+               PagingAndSortingRepository<AdDescription, Long>,
+               /** https://github.com/spring-projects/spring-data-envers/pull/45 QueryDslPredicateExecutor<AdDescription>, **/
+               RevisionRepository<AdDescription, Long, Integer> {
 
        // Custom Query method (useful when the offered methods by PagingAndSortingRepository are not enough)
        Page<AdDescription> findByAd(Ad ad, Pageable pageable);
index bc73359..c0add01 100644 (file)
@@ -3,6 +3,7 @@ package de.spring.example.persistence.repository;
 import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
 import org.springframework.data.jpa.repository.Query;
 import org.springframework.data.repository.PagingAndSortingRepository;
+import org.springframework.data.repository.history.RevisionRepository;
 import org.springframework.data.repository.query.Param;
 
 import de.spring.example.persistence.domain.Ad;
@@ -14,7 +15,10 @@ import de.spring.example.persistence.domain.Ad;
  * Be careful with <code>@Transactional</code>. SimpleJpaRepository has annotated methods.
  *
  */
-public interface AdRepository extends PagingAndSortingRepository<Ad, Long>, JpaSpecificationExecutor<Ad> {
+public interface AdRepository extends
+               PagingAndSortingRepository<Ad, Long>,
+               JpaSpecificationExecutor<Ad>,
+               RevisionRepository<Ad, Long, Integer> {
        
        // Named Native Query (using the native language of the store) It is not portable.
        // See de.spring.persistence.example.domain.Ad
index 5c95de1..bcdd8a3 100644 (file)
        <context:annotation-config />\r
 \r
     <context:component-scan base-package="de.spring.example.persistence" />\r
+\r
+       <jpa:repositories entity-manager-factory-ref="entityManagerFactory"\r
+               base-package="de.spring.example.persistence.**.repository"\r
+               transaction-manager-ref="transactionManager"\r
+               factory-class="org.springframework.data.envers.repository.support.EnversRevisionRepositoryFactoryBean" />\r
         \r
        <bean id="entityManagerFactory"\r
                class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">\r
@@ -48,8 +53,6 @@
        </property>\r
        </bean>\r
 \r
-       <jpa:repositories entity-manager-factory-ref="entityManagerFactory"\r
-               base-package="de.spring.example.persistence.**.repository"\r
-               transaction-manager-ref="transactionManager" />\r
+\r
 \r
 </beans>\r
index 7f5a681..830709b 100644 (file)
@@ -45,7 +45,10 @@ public class AdDescriptionServiceImpl
                final QAdDescription adDescription = QAdDescription.adDescription1;
                final BooleanExpression adDescriptionHasAdLink = adDescription.adLink.contains("gumartinm");
                final BooleanExpression adDescriptionHasDescription = adDescription.adDescription.contains("babucha");
-               
-               return repository.findAll(adDescriptionHasAdLink.and(adDescriptionHasDescription), pageRequest);
+               /**
+                * https://github.com/spring-projects/spring-data-envers/pull/45
+                * return repository.findAll(adDescriptionHasAdLink.and(adDescriptionHasDescription), pageRequest);
+                */
+               return null;
        }
 }