Search code examples
mapstruct

Does mapstruct work with JPA meta model classes?


I am getting a compile error:

com/mycompany/hibernate5/Main.java:[10,46] cannot find symbol
  symbol:   class Customer_
  location: package com.mycompany.hibernate5.sakila.domain
com/mycompany/hibernate5/Main.java:[11,46] cannot find symbol
  symbol:   class Address_
  location: package com.mycompany.hibernate5.sakila.domain
2 errors 

However when I remove the mapstruct annotation processor it compiles fine.

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.5.1</version>
<!--                <configuration>
                    <annotationProcessorPaths>
                        <path>
                            <groupId>org.mapstruct</groupId>
                            <artifactId>mapstruct-processor</artifactId>
                            <version>${org.mapstruct.version}</version>
                        </path>
                    </annotationProcessorPaths>
                </configuration>-->
            </plugin>

So I think that mapstruct is scanning the classes before they have been generated? Any solutions for this?


Solution

  • I added the hibernate JPA modelgen jar to the path

    <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.5.1</version>
                <configuration>
                    <annotationProcessorPaths>
                        <path>
                            <groupId>org.mapstruct</groupId>
                            <artifactId>mapstruct-processor</artifactId>
                            <version>${org.mapstruct.version}</version>
                        </path>
                        <path>
                            <groupId>org.hibernate</groupId>
                            <artifactId>hibernate-jpamodelgen</artifactId>
                            <version>5.2.6.Final</version>
                        </path>
                    </annotationProcessorPaths>
                </configuration>
            </plugin>
    

    Now it is working, thanks