Cosium / spring-data-jpa-entity-graph

Spring Data JPA extension allowing full dynamic usage of EntityGraph on repositories
MIT License
469 stars 52 forks source link

MappedSuperclass annotation issue #16

Closed pimuzzo closed 6 years ago

pimuzzo commented 6 years ago

Hi, I am using 1.11.03 and I have the spring configuration in xml in this way:

    <jpa:repositories base-package="my.package.datamodel.repositories"
                      factory-class="com.cosium.spring.data.jpa.entity.graph.repository.support.EntityGraphJpaRepositoryFactoryBean"
                      entity-manager-factory-ref="entityManagerFactory" />

I have some classes annotated with @MappedSuperclass and I have this issue:

java.lang.IllegalArgumentException: Not an entity: class com.liberologico.cloudesire.datamodel.entities.MetadataEntity
    at org.hibernate.metamodel.internal.MetamodelImpl.entity(MetamodelImpl.java:456)
    at org.hibernate.metamodel.internal.MetamodelImpl.findEntityGraphsByType(MetamodelImpl.java:687)
    at org.hibernate.internal.SessionFactoryImpl.findEntityGraphsByType(SessionFactoryImpl.java:545)
    at org.hibernate.internal.SessionImpl.getEntityGraphs(SessionImpl.java:3856)
    at org.springframework.orm.jpa.ExtendedEntityManagerCreator$ExtendedEntityManagerInvocationHandler.invoke(ExtendedEntityManagerCreator.java:347) [3 skipped]
    at com.sun.proxy.$Proxy166.getEntityGraphs(Unknown Source)
    at org.springframework.orm.jpa.SharedEntityManagerCreator$SharedEntityManagerInvocationHandler.invoke(SharedEntityManagerCreator.java:298) [3 skipped]
    at com.sun.proxy.$Proxy166.getEntityGraphs(Unknown Source)
    at com.cosium.spring.data.jpa.entity.graph.repository.support.RepositoryEntityManagerEntityGraphInjector.invoke(RepositoryEntityManagerEntityGraphInjector.java:59) [6 skipped]
    at com.sun.proxy.$Proxy169.getEntityGraphs(Unknown Source) [2 skipped]
    at com.cosium.spring.data.jpa.entity.graph.repository.support.RepositoryMethodEntityGraphExtractor$JpaEntityGraphMethodInterceptor.findDefaultEntityGraph(RepositoryMethodEntityGraphExtractor.java:88)
    at com.cosium.spring.data.jpa.entity.graph.repository.support.RepositoryMethodEntityGraphExtractor$JpaEntityGraphMethodInterceptor.<init>(RepositoryMethodEntityGraphExtractor.java:79)
    at com.cosium.spring.data.jpa.entity.graph.repository.support.RepositoryMethodEntityGraphExtractor.postProcess(RepositoryMethodEntityGraphExtractor.java:46)
reda-alaoui commented 6 years ago

Hi @pimuzzo ,

Can you show me the used repository class and repository method call that generates this exception?

reda-alaoui commented 6 years ago

@pimuzzo , did you solve your issue?

pimuzzo commented 6 years ago

Not yet, I'll try to debug it better and write a test, if you want we can close it for now, and I'll open again if necessary

reda-alaoui commented 6 years ago

@pimuzzo , ok, reopen when ready ;)

pimuzzo commented 6 years ago

Well, I fixed it!!! Sorry if I am late. I've this situation: first @Entity public class SubscriptionMetadata extends MetadataEntity second @Entity public class CustomerMetadata extends MetadataEntity a @MappedSuperclass public abstract class MetadataEntity extends BaseEntityId

And the repository was:

public interface MetadataRepository extends JpaRepository<MetadataEntity, Integer>
{
    CustomerMetadata findByCompanyAndUser( Company company, User user );

    SubscriptionMetadata findBySubscription( Subscription subscription );
}

And to make it works I've splitted it in 2 repositories SubscriptionMetadataRepository and CustomerMetadataRepository.

Thanks for your hint to watch the repositories ;)

reda-alaoui commented 6 years ago

Ok thanks for the feedback :+1: