Hibernate ORM

Tooling

Hibernate offers a series of tools for developers to use in their tool chain. The most prominent being Hibernate Tools which is a set of Eclipse plugins and part of JBoss Tools. But there is more …​

Hibernate Metamodel Generator

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. For example, for the class Order:

@Entity
public class Order {
    @Id
    @GeneratedValue
    Integer id;
    @ManyToOne
    Customer customer;
    @OneToMany
    Set<Item> items;
    BigDecimal totalCost;
    // standard setter/getter methods
}

It would generate the metamodel class Order_:

@StaticMetamodel(Order.class)
public class Order_ {
    public static volatile SingularAttribute<Order, Integer> id;
    public static volatile SingularAttribute<Order, Customer> customer;
    public static volatile SetAttribute<Order, Item> items;
    public static volatile SingularAttribute<Order, BigDecimal> totalCost;
}

Which in turn allows to write queries like this:

CriteriaBuilder cb = entityManager.getCriteriaBuilder();
CriteriaQuery<Order> cq = cb.createQuery(Order.class);
SetJoin<Order, Item> itemNode = cq.from(Order.class).join(Order_.items);
cq.where( cb.equal(itemNode.get(Item_.id), 5 ) ).distinct(true);

To use Hibernate Metamodel Generator you can add it as an annotation processor to your classpath: find details on how to do that here for Gradle and here for Maven.

For more information and setup options refer to the online documentation.

Prior to Hibernate ORM 4.3, Hibernate Metamodel Generator was hosted as a stand-alone project. As of ORM 4.3 it is part of the main ORM release. Issues should be reported in the ORM issue tracker.

Back to top