Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support @UseBookmark in composed annotations. [DATAGRAPH-1115] #1676

Closed
spring-projects-issues opened this issue Aug 21, 2018 · 2 comments
Closed
Assignees
Labels
in: core Issues in core support type: bug A general bug

Comments

@spring-projects-issues
Copy link

spring-projects-issues commented Aug 21, 2018

Torsten Kuhnhenne opened DATAGRAPH-1115 and commented

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)

Affects: 5.0.9 (Kay SR9)

Backported to: 5.0.10 (Kay SR10)

@spring-projects-issues
Copy link
Author

spring-projects-issues commented Aug 24, 2018

Gerrit Meier commented

Thanks for reporting this. The solution will be available in Lovelace and then also get merged into into Kay

@spring-projects-issues
Copy link
Author

spring-projects-issues commented Aug 24, 2018

Torsten Kuhnhenne commented

Thank you for the quick fix :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core support type: bug A general bug
Projects
None yet
Development

No branches or pull requests

2 participants