Maven generated static metamodels in Hibernate 5.2 not recognized by DAO classes

1.1k views Asked by At

I have successfully generated metamodels and all metamodel classes are outputted in target/annotations directory. But my problem is that my other classes such as DAOImpl doesn't recognize these metamodel generated classes. Any help please?

Here is how I generate metamodels using my maven project's pom.xml file:

<plugin>
  <groupId>org.bsc.maven</groupId>
  <artifactId>maven-processor-plugin</artifactId>
  <executions>
    <execution>
      <id>process</id>
      <goals>
        <goal>process</goal>
      </goals>
      <phase>generate-sources</phase>
      <configuration>
        <processors>
          <processor>org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor</processor>
        </processors>
      </configuration>
    </execution>
  </executions>
  <dependencies>
    <dependency>        
      <groupId>org.hibernate</groupId>
      <artifactId>hibernate-jpamodelgen</artifactId>
      <version>4.3.4.Final</version>
    </dependency>
  </dependencies>
</plugin>
1

There are 1 answers

0
Saulius Next On BEST ANSWER

Check do you have set this:

 <plugin> <!--Compiler instructions to generate model, add to sources.-->

    <artifactId>maven-compiler-plugin</artifactId>

    <configuration>

        <source>1.6</source>

        <target>1.6</target>

        <compilerArguments>

            <processor>org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor</processor>

        </compilerArguments>

    </configuration>

</plugin>


<plugin><!--path were to generate model, add to -->

    <groupId>org.bsc.maven</groupId>

    <artifactId>maven-processor-plugin</artifactId>

    <executions>

        <execution>

            <id>process</id>

            <goals>

                <goal>process</goal>

            </goals>

            <phase>generate-sources</phase>

            <configuration>

                <!-- source output directory -->

                <outputDirectory>target/metamodel</outputDirectory>

            </configuration>

        </execution>

    </executions>

</plugin>

<plugin>

    <groupId>org.codehaus.mojo</groupId>

    <artifactId>build-helper-maven-plugin</artifactId>

    <version>1.3</version>

    <executions>

        <execution>

            <id>add-source</id>

            <phase>generate-sources</phase>

            <goals>

                <goal>add-source</goal>

            </goals>

            <configuration>

                <sources>

                    <source>target/metamodel</source>

                </sources>

            </configuration>

        </execution>

    </executions>

</plugin>

I think main problem is that folder where you generated classes isn't linked to project sources. You should tell your project that this directory is source folder or generate everything under src directory.