Cosium / spring-data-jpa-entity-graph

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

spring-data-jpa-entity-graph-generator doesn't generate #43

Closed jamestrandung closed 4 years ago

jamestrandung commented 4 years ago

Following documentation, I added the following dependencies.

    <dependency>
      <groupId>com.cosium.spring.data</groupId>
      <artifactId>spring-data-jpa-entity-graph</artifactId>
      <version>${spring-data-jpa-entity-graph.version}</version>
    </dependency>
    <dependency>
      <groupId>com.cosium.spring.data</groupId>
      <artifactId>spring-data-jpa-entity-graph-generator</artifactId>
      <version>${spring-data-jpa-entity-graph.version}</version>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>org.hibernate</groupId>
      <artifactId>hibernate-jpamodelgen</artifactId>
      <scope>provided</scope>
    </dependency>

In my class, when I try to access the generated EntityGraph after compiling the project, the IDE cannot find such class. Is there something else I need to do?

image

Versions:

reda-alaoui commented 4 years ago

Is this only an IDE issue? The classes should have been generated in your target directory, is that the case? If yes, you have to mark the directory of the generated classes (target/annotations if I remember well) as « generated sources ». If not, are the hibernate metadata generated? If not, annotation processors are being ignored by your maven config or ide settings for a reason you will have to dig about.

reda-alaoui commented 4 years ago

The classes are generated in target/generated-sources/annotations

jamestrandung commented 4 years ago

@reda-alaoui Hi. Thanks for your comments. I actually have no idea how this generator is supposed to work. I just noticed its existence recently after using the main library for quite some time.

My assumption was that it should work like Lombok, meaning after I add in the spring-data-jpa-entity-graph-generator library, I should be able to access the generated class just like how I access Lombok builder via @Builder annotation. I do see the generated class from Lombok in the target directory. However, I'm not seeing anything with EntityGraph suffix.

image

If yes, you have to mark the directory of the generated classes (target/annotations if I remember well) as « generated sources ».

If not, are the hibernate metadata generated? If not, annotation processors are being ignored by your maven config or ide settings for a reason you will have to dig about.

If my assumption is wrong and the generator library requires some specific settings to work, can you explain more on what I need to do? I don't have anything special in my pom.xml that instructs Hibernate to ignore specific package/folder.

jamestrandung commented 4 years ago

@reda-alaoui My generated-sources folder is empty.

image

reda-alaoui commented 4 years ago

That means annotation processing is ignored for some reason.

spring-data-jpa-entity-graph-generator and hibernate-jpamodelgen are Annotation Processors. When in the compilation classpath, they should automatically be detected by javac (Java compiler). This is the case for our company builds.

I don't know if Lombok is a basic annotation processor but there is plenty of web resources explaining how to fix Annotation Processor malfunction.

reda-alaoui commented 4 years ago

You can also read that => https://docs.jboss.org/hibernate/orm/5.0/topical/html/metamodelgen/MetamodelGenerator.html

reda-alaoui commented 2 years ago

I created https://github.com/Cosium/spring-data-jpa-entity-graph-sample which is a demo application for this extension. The demo uses the generator and the generated entity graphs.