How to create a JPA 2.0 metamodel?

In the spirit of security, the type associated with CriteriaQuery JPA 2.0 also has an API to support the Metamodel view of objects.

Does anyone know of a fully functional implementation of this API (for generating a metamodel as opposed to creating metamodel classes manually)? It would be great if someone also knew the steps for setting this up in Eclipse (I assume this is as simple as setting up an annotation processor, but you never know).

EDIT: Just stumbled upon a Hibernate JPA 2 Metamodel Generator . But the problem remains, since I cannot find download links for jar.

EDIT 2: It has been so much time since I asked this question, but I thought I'd come back and add a link to the Hibernate JPA Model Generator project on SourceForge

+71
java jpa annotation-processing metamodel
Jun 14 '10 at 13:32
source share
5 answers

It would be great if someone also knew the steps to configure this in Eclipse (I assume this is as simple as setting up an annotation processor, but you never know)

Yes it is. The following are implementations and instructions for the various versions of JPA 2.0:

Eclipselink

Hibernate

Openjpa

DataNucleus




The latest version of Hibernate is available at:

Older version of sleep mode:

+75
Jun 14 '10 at 13:59
source share

REVISED (March / 2014)

Please take a look at jpa-metamodels-with-maven

Hibernate

Hibernate is recommended.

(I do not consider any functions / functions / capabilities / stabilizers for these implementations. And the above statement focuses only on the use of maven that I built.)

 <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> 

Openjpa

OpenJPA seems to require an additional <openjpa.metamodel>true<openjpa.metamodel> .

 <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.apache.openjpa.persistence.meta.AnnotationProcessor6</processor> </processors> <optionMap> <openjpa.metamodel>true</openjpa.metamodel> </optionMap> </configuration> </execution> </executions> <dependencies> <dependency> <groupId>org.apache.openjpa</groupId> <artifactId>openjpa</artifactId> <version>2.3.0</version> </dependency> </dependencies> </plugin> 

Eclipselink

EclipseLink requires persistence.xml .

 <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.eclipse.persistence.internal.jpa.modelgen.CanonicalModelProcessor</processor> </processors> </configuration> </execution> </executions> <dependencies> <dependency> <groupId>org.eclipse.persistence</groupId> <artifactId>org.eclipse.persistence.jpa.modelgen.processor</artifactId> <version>2.5.1</version> </dependency> </dependencies> </plugin> 

==========================================

For Apache Maven users,

After a simple setup, it seems to work. ( with old maven compiler plugin, updated. )

 <!-- This method doesn't work with newest maven-compiler-plugin --> <!-- But if it ok to work with old maven-compiler-plugin --> <!-- This is the best method --> <!-- There is no other required configurations --> <!-- We don't even require to config any processor names --> <project> <build> <extensions> <extension> <groupId>org.hibernate</groupId> <artifactId>hibernate-jpamodelgen</artifactId> <version>1.3.0.Final</version> </extension> </extensions> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>2.5.1</version> <!-- this is critical --> <configuration> <source>1.6</source> <target>1.6</target> </configuration> </plugin> </plugins> </build> </project> 

you can run it using "mvn compiler: compile"

UPDATE

Note that this method only works with that old maven-compiler-plugin. Check the version in code.

+35
Jun 28 2018-12-12T00:
source share

Support for Eclipse JPA 2.0 via Dali (which is included in the "Eclipse IDE for JEE Developers") has its own metamodel generator integrated with Eclipse.

  • Select a project in Package Explorer
  • Go to the PropertiesJPA dialog
  • Select the source folder from the canonical metamodel (JPA 2.0) .
  • Click Apply to generate metamodel classes in the selected source folder.

enter image description here

This should work on any JPA provider, since the generated classes are standard.

Also see here .

+14
Jun 28 2018-12-12T00:
source share

For eclipselink, only the following dependency is enough to generate a metamodel. Nothing more is needed.

  <dependency> <groupId>org.eclipse.persistence</groupId> <artifactId>org.eclipse.persistence.jpa.modelgen.processor</artifactId> <version>2.5.1</version> <scope>provided</scope> </dependency> 
+5
Jun 09 '14 at 11:47
source share

For Hibernate as the provider that is the most common IMHO:

In the case of creating tools such as Gradle, Maven, you need to create a Jibernate JPA 2 Metamodel Generator jar in the path to the classes and compiler level> = 1.6, this is all you need to build the project, and the metamodel will be generated automatically.

In case of IDE Eclipse 1. goto Project-> Properties-> Java Compiler-> Annotation Processing and enable it. 2. Expand Annotation Processing → Factory Path-> Add External Bank Add Hibernate JPA 2 Metamodel Generator Bank Check the newly added bank and say “OK”. Clean and build!

Link Hibernate JPA 2 Link to the generator metamodel from maven repo https://mvnrepository.com/artifact/org.hibernate/hibernate-jpamodelgen

+1
Jul 13 '16 at 9:35
source share



All Articles