Overview

I have already reported this issue on Stack Overflow.

Desc : Spring JPA does not recognize my custom @MyEntity annotation instead of @javax.persistence.Entity annotation.

Related Issues

  • 15425

Expectations

Existing:

public class DefaultPersistenceUnitManager
        implements PersistenceUnitManager, ResourceLoaderAware, LoadTimeWeaverAware, InitializingBean {

private static final Set<AnnotationTypeFilter> entityTypeFilters;
static {
        entityTypeFilters = new LinkedHashSet<>(8);
        entityTypeFilters.add(new AnnotationTypeFilter(Entity.class, false));
        entityTypeFilters.add(new AnnotationTypeFilter(Embeddable.class, false));
        entityTypeFilters.add(new AnnotationTypeFilter(MappedSuperclass.class, false));
        entityTypeFilters.add(new AnnotationTypeFilter(Converter.class, false));
    }

To be:

static {
    entityTypeFilters = new LinkedHashSet<>(8);
    entityTypeFilters.add(new AnnotationTypeFilter(Entity.class, false));
    entityTypeFilters.add(new AnnotationTypeFilter(Embeddable.class, false));
    entityTypeFilters.add(new AnnotationTypeFilter(MappedSuperclass.class, false));
    entityTypeFilters.add(new AnnotationTypeFilter(Converter.class, false));
    entityTypeFilters.add(new AnnotationTypeFilter(MyEntity.class, false)); // ADDED
}

Comment From: sbrannen

As a side note, if were to make any changes in this area, we would never be able to make Spring's code directly dependent on a custom type from your project.

Rather, we would likely introduce support for finding @Entity when used as a meta-annotation; however, I am not sure that JPA/Hibernate support that. In any case, no JPA provider would support Spring's @AliasFor annotation as suggested in the linked Stack Overflow question.

Comment From: sbrannen

Since we are not aware of any JPA provider that supports @Entity when used as meta-annotation, we are closing this issue.