Search
Hibernate Metamodel Generator

Hibernate Metamodel Generator

Relational Persistence for Java and .NET

Hibernate Metamodel Generator

JPA 2 defines a new typesafe Criteria API which allows criteria queries to be constructed in a strongly-typed manner, using metamodel objects to provide type safety. For developers it is important that the task of the metamodel generation can be automated. Hibernate Metamodel Generator is an annotation processor based on the  Pluggable Annotation Processing API with the task of creating JPA 2 static metamodel classes. The following example shows how the metamodel class for the class Order looks like:

 

<pre class="programlisting"><a id="jpa2-entity-example">@Entity<br />public class Order {<br />    @Id <br />    @GeneratedValue<br />    Integer id;    <br />    @ManyToOne <br />    Customer customer;   <br />    @OneToMany <br />    Set&lt;Item&gt; items;<br />    BigDecimal totalCost;    <br />    // standard setter/getter methods<br />}<br /></a></pre>

<pre class="programlisting"><a id="metamodel-class-example">@StaticMetamodel(Order.class)<br />public class Order_ {<br />    public static volatile SingularAttribute&lt;Order, Integer&gt; id;<br />    public static volatile SingularAttribute&lt;Order, Customer&gt; customer;<br />    public static volatile SetAttribute&lt;Order, Item&gt; items;<br />    public static volatile SingularAttribute&lt;Order, BigDecimal&gt; totalCost;<br />}<br /></a></pre>