Uploaded image for project: 'Spring Data Neo4j'
  1. Spring Data Neo4j
  2. DATAGRAPH-1115

Support @UseBookmark in composed annotations.

    Details

      Description

      I want to use a composed annotation that combines @Transactional and @UseBookmark but the pointcut does not find the @UseBookmark annotation in such cases.

       

      The problem is that targetClass.getAnnotation() does not handle composed annotation. I think that AnnotationUtils from Spring must be used in BookmarkOperationPointcut instead.

       

      A little test case to illustrate the problem and solution:

      package de.myview.xom;
      
      import java.lang.annotation.Documented;
      import java.lang.annotation.ElementType;
      import java.lang.annotation.Inherited;
      import java.lang.annotation.Retention;
      import java.lang.annotation.RetentionPolicy;
      import java.lang.annotation.Target;
      
      import org.junit.jupiter.api.Test;
      import org.springframework.core.annotation.AnnotationUtils;
      import org.springframework.data.neo4j.annotation.UseBookmark;
      import org.springframework.transaction.annotation.Propagation;
      import org.springframework.transaction.annotation.Transactional;
      
      public class AnnotationUtilsTest {
      
          @Test
          public void test() {
              final Class<?> clazz1 = MyTest1.class;
      
              UseBookmark classAnnotation = clazz1.getAnnotation( UseBookmark.class );
              // classAnnotation is null!
              System.err.println( classAnnotation );
      
              UseBookmark anno = AnnotationUtils.findAnnotation( clazz1, UseBookmark.class );
              // classAnnotation is not null (expected behaviour!)
              System.err.println( anno );
      
              // Works as expected
              final Class<?> clazz2 = MyTest2.class;
              classAnnotation = clazz2.getAnnotation( UseBookmark.class );
              System.err.println( classAnnotation );
              anno = AnnotationUtils.findAnnotation( clazz2, UseBookmark.class );
              System.err.println( anno );
      
          }
      
          @Target({ ElementType.METHOD, ElementType.TYPE })
          @Retention(value = RetentionPolicy.RUNTIME)
          @Inherited
          @Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = Exception.class)
          @UseBookmark
          @Documented
          public @interface MyTransactional {
      
          }
      
          @MyTransactional
          public class MyTest1 {
      
          }
      
          @Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = Exception.class)
          @UseBookmark
          public class MyTest2 {
      
          }
      }
      

      Output of the test is:

      null
      @org.springframework.data.neo4j.annotation.UseBookmark(value=true)
      @org.springframework.data.neo4j.annotation.UseBookmark(value=true)
      @org.springframework.data.neo4j.annotation.UseBookmark(value=true)
      

        Attachments

          Activity

            People

            • Assignee:
              michael.simons Michael Simons
              Reporter:
              torsten.kuhnhenne Torsten Kuhnhenne
              Last updater:
              Mark Paluch
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: