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

Getting Started #15

Closed jordanbaucke closed 6 years ago

jordanbaucke commented 6 years ago

I have followed [2.0 quickstart guide](https://github.com/Cosium/spring-data-jpa-entity-graph/blob/master/doc/MAIN.md,

In my database configuration I had:

@Configuration
@EnableJpaRepositories("com.mypackage.api.repository")
@EnableJpaAuditing(auditorAwareRef = "springSecurityAuditorAware")
@EnableTransactionManagement
@EnableElasticsearchRepositories("com.mypackage.api.repository.search")
public class DatabaseConfiguration {
    @Bean
    public Hibernate5Module hibernate5Module() {
        return new Hibernate5Module();
    }
}

Now if I switch:

@EnableJpaRepositories("com.mypackage.api.repository")

to:

@EnableJpaRepositories(repositoryFactoryBeanClass = EntityGraphJpaRepositoryFactoryBean.class)

I than add a new repository:

public interface UserEntityGraphRepository extends EntityGraphJpaRepository<User, Long> {
}

in addition to:

public interface UserRepository extends JpaRepository<User, Long> {
}

I get exception:

java.lang.IllegalStateException: Failed to load ApplicationContext ... Caused by: org.springframework.data.mapping.PropertyReferenceException: No property findAll found for type User!

If I just replace extends JpaRepository w/ EntityGraphJpaRepository, I get:

Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userDetailsService': Unsatisfied dependency expressed through field 'userRepository'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userRepository': Invocation of init method failed; nested exception is org.springframework.data.mapping.PropertyReferenceException: No property findOne found for type User!

reda-alaoui commented 6 years ago

Your issue looks like https://github.com/Cosium/spring-data-jpa-entity-graph/issues/8 Are you certain that @EnableJpaRepositories(repositoryFactoryBeanClass = EntityGraphJpaRepositoryFactoryBean.class) was taken into account?

Can you put a breakpoint in the factoryBean class to check it is the one that is used?

Also can I see the User class? And could you try to disable Elasticsearch and/or Auditing to see if the issue could come from here?

jordanbaucke commented 6 years ago

@reda-alaoui which factory bean class?

reda-alaoui commented 6 years ago

EntityGraphJpaRepositoryFactoryBean

jordanbaucke commented 6 years ago

@reda-alaoui

Here is User Class (relevant parts at least) https://gist.github.com/jordanbaucke/125f7a47eb224aeeb25d4b40ecf41f6e,

And current UseRepository: https://gist.github.com/jordanbaucke/7b14b3c939774b59063d980feb191016

I do not get to loading EntityGraphJpaRepositoryFactoryBean, as SpringSecurity kicks in and throws:

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'dataInitalizer': Unsatisfied dependency expressed through field 'dataInitializationService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'dataInitializationServiceImpl': Unsatisfied dependency expressed through field 'passwordEncoder'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'securityConfiguration': Unsatisfied dependency expressed through field 'userDetailsService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userDetailsService': Unsatisfied dependency expressed through field 'userRepository'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userRepository': Invocation of init method failed; nested exception is org.springframework.data.mapping.PropertyReferenceException: No property getOne found for type User!

2017-10-31_11-52-18

reda-alaoui commented 6 years ago

I see a compilation error inside the dependency. What version of Spring Data are you using? Can you paste the relevant pom.xml or gradle files parts?

jordanbaucke commented 6 years ago
  compile "org.springframework.boot:spring-boot-starter-data-jpa"
...
    compile "com.cosium.spring.data:spring-data-jpa-entity-graph:2.0.0"

??

reda-alaoui commented 6 years ago

I need to know which version of https://github.com/spring-projects/spring-data-jpa you are using.

jordanbaucke commented 6 years ago

Sorry:

Appears to be org.springframework.data:spring-data-jpa:1.10.5.RELEASE, so I should change my version of com.cosium.spring.data:spring-data-jpa-entity-graph:2.0.0

~/Documents/workspace/api$ gradle dependencies | grep spring-data
|    +--- org.springframework.data:spring-data-jpa:1.10.5.RELEASE
|    |    +--- org.springframework.data:spring-data-commons:1.12.5.RELEASE
|    \--- org.springframework.data:spring-data-elasticsearch:2.0.5.RELEASE
|         +--- org.springframework.data:spring-data-commons:1.12.5.RELEASE (*)
|    +--- org.springframework.data:spring-data-commons:1.12.2.RELEASE -> 1.12.5.RELEASE (*)
+--- com.cosium.spring.data:spring-data-jpa-entity-graph:2.0.0
|    +--- org.springframework.data:spring-data-jpa:1.10.5.RELEASE
|    |    +--- org.springframework.data:spring-data-commons:1.12.5.RELEASE
|    \--- org.springframework.data:spring-data-elasticsearch:2.0.5.RELEASE
|         +--- org.springframework.data:spring-data-commons:1.12.5.RELEASE (*)
|    +--- org.springframework.data:spring-data-commons:1.12.2.RELEASE -> 1.12.5.RELEASE (*)
+--- com.cosium.spring.data:spring-data-jpa-entity-graph:2.0.0
|    +--- org.springframework.data:spring-data-jpa:1.10.5.RELEASE
|    |    +--- org.springframework.data:spring-data-commons:1.12.5.RELEASE
|    \--- org.springframework.data:spring-data-elasticsearch:2.0.5.RELEASE
|         +--- org.springframework.data:spring-data-commons:1.12.5.RELEASE (*)
|    +--- org.springframework.data:spring-data-commons:1.12.2.RELEASE -> 1.12.5.RELEASE (*)
\--- com.cosium.spring.data:spring-data-jpa-entity-graph:2.0.0
|    +--- org.springframework.data:spring-data-jpa:1.10.5.RELEASE
|    |    +--- org.springframework.data:spring-data-commons:1.12.5.RELEASE
|    \--- org.springframework.data:spring-data-elasticsearch:2.0.5.RELEASE
|         +--- org.springframework.data:spring-data-commons:1.12.5.RELEASE (*)
|    +--- org.springframework.data:spring-data-commons:1.12.2.RELEASE -> 1.12.5.RELEASE (*)
+--- com.cosium.spring.data:spring-data-jpa-entity-graph:2.0.0
|    +--- org.springframework.data:spring-data-jpa:1.10.5.RELEASE
|    |    +--- org.springframework.data:spring-data-commons:1.12.5.RELEASE
|    \--- org.springframework.data:spring-data-elasticsearch:2.0.5.RELEASE
|         +--- org.springframework.data:spring-data-commons:1.12.5.RELEASE (*)
|    +--- org.springframework.data:spring-data-commons:1.12.2.RELEASE -> 1.12.5.RELEASE (*)
+--- com.cosium.spring.data:spring-data-jpa-entity-graph:2.0.0
|    +--- org.springframework.data:spring-data-jpa:1.10.5.RELEASE
|    |    +--- org.springframework.data:spring-data-commons:1.12.5.RELEASE
|    \--- org.springframework.data:spring-data-elasticsearch:2.0.5.RELEASE
|         +--- org.springframework.data:spring-data-commons:1.12.5.RELEASE (*)
|    +--- org.springframework.data:spring-data-commons:1.12.2.RELEASE -> 1.12.5.RELEASE (*)
+--- com.cosium.spring.data:spring-data-jpa-entity-graph:2.0.0
|    +--- org.springframework.data:spring-data-jpa:1.10.5.RELEASE
|    |    +--- org.springframework.data:spring-data-commons:1.12.5.RELEASE
|    \--- org.springframework.data:spring-data-elasticsearch:2.0.5.RELEASE
|         +--- org.springframework.data:spring-data-commons:1.12.5.RELEASE (*)
|    +--- org.springframework.data:spring-data-commons:1.12.2.RELEASE -> 1.12.5.RELEASE (*)
+--- com.cosium.spring.data:spring-data-jpa-entity-graph:2.0.0
|    +--- org.springframework.data:spring-data-jpa:1.10.5.RELEASE
|    |    +--- org.springframework.data:spring-data-commons:1.12.5.RELEASE
|    \--- org.springframework.data:spring-data-elasticsearch:2.0.5.RELEASE
|         +--- org.springframework.data:spring-data-commons:1.12.5.RELEASE (*)
|    +--- org.springframework.data:spring-data-commons:1.12.2.RELEASE -> 1.12.5.RELEASE (*)
+--- com.cosium.spring.data:spring-data-jpa-entity-graph:2.0.0
|    +--- org.springframework.data:spring-data-jpa:1.10.5.RELEASE
|    |    +--- org.springframework.data:spring-data-commons:1.12.5.RELEASE
|    \--- org.springframework.data:spring-data-elasticsearch:2.0.5.RELEASE
|         +--- org.springframework.data:spring-data-commons:1.12.5.RELEASE (*)
|    +--- org.springframework.data:spring-data-commons:1.12.2.RELEASE -> 1.12.5.RELEASE (*)
+--- com.cosium.spring.data:spring-data-jpa-entity-graph:2.0.0
reda-alaoui commented 6 years ago

Yes you must use a 1.10.x version of this library.