Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to generate the JPA entity Metamodel?

In the spirit of type safety associated with the CriteriaQuery JPA 2.0 also has an API to support Metamodel representation of entities.

Is anyone aware of a fully functional implementation of this API (to generate the Metamodel as opposed to creating the metamodel classes manually)? It would be awesome if someone also knows the steps for setting this up in Eclipse (I assume it's as simple as setting up an annotation processor, but you never know).

EDIT: Just stumbled across Hibernate JPA 2 Metamodel Generator . But the issue remains since I can't find any download links for the jar.

EDIT 2: Awhile has passed 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

like image 693
Andrey Avatar asked Jun 14 '10 13:06

Andrey


People also ask

What is metamodel in JPA?

The JPA Metamodel API provides the ability to examine the persistent object model and retrieve details on managed classes and persistent fields and properties, similarly to the ability that Java reflection provides for general Java types.

What is metamodel entity?

The Metamodel API is used to create a metamodel of the managed entities in a particular persistence unit. For each entity class in a particular package, a metamodel class is created with a trailing underscore and with attributes that correspond to the persistent fields or properties of the entity class.

What is Hibernate metamodel?

Hibernate Metamodel Generator is an annotation processor automating the generation of the static metamodel classes needed for typesafe Criteria queries as defined by JPA 2.

What is SingularAttribute?

Interface SingularAttribute<X,T> Superinterfaces: Attribute<X,T> , Bindable<T> Instances of the type SingularAttribute represents persistent single-valued properties or fields. Class<T> getBindableJavaType() Return the Java type of the represented object.


1 Answers

It would be awesome if someone also knows the steps for setting this up in Eclipse (I assume it's as simple as setting up an annotation processor, but you never know)

Yes it is. Here are the implementations and instructions for the various JPA 2.0 implementations:

EclipseLink

  • org.eclipse.persistence.internal.jpa.modelgen.CanonicalModelProcessor

Hibernate

  • org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor
  • http://in.relation.to/2009/11/09/hibernate-static-metamodel-generator-annotation-processor

OpenJPA

  • org.apache.openjpa.persistence.meta.AnnotationProcessor6
  • http://openjpa.apache.org/builds/2.4.1/apache-openjpa/docs/ch13s04.html

DataNucleus

  • org.datanucleus.jpa.JPACriteriaProcessor
  • http://www.datanucleus.org/products/accessplatform_2_1/jpa/jpql_criteria_metamodel.html

The latest Hibernate implementation is available at:

  • https://mvnrepository.com/artifact/org.hibernate/hibernate-jpamodelgen/

An older Hibernate implementation is at:

  • http://repository.jboss.com/maven2/org/hibernate/hibernate-jpamodelgen/1.0.0.Final/hibernate-jpamodelgen-1.0.0.Final.jar
like image 156
Pascal Thivent Avatar answered Oct 18 '22 14:10

Pascal Thivent