Mastering Java EE Development with WildFly
上QQ阅读APP看书,第一时间看更新

Persistence

Persistence is a key feature in the Java EE. Application servers compliant with the Java EE 7 specifications provide Java Persistence API (JPA) 2.1 implementations for it. JPA was born with Java EE 5 moving from the old Entity Beans 2.x with the goal to give standard specifications on how to persist objects inside relational databases.

There exists many JPA implementations such as EclipseLink, Oracle TopLink, OpenJPA, and Hibernate. WildFly since JBoss 4.x a is built under Hibernate.

Hibernate 5 is the community product that manages as default JPA provider the persistence in WildFly 10. Although WildFly is built with a modular architecture where you can choose the versions of the core products by configuration or automatic import of libraries, we will focus in this chapter on the default Hibernate version provided by WildFly 10.1.0. The default version is the 5.0.10. Here are the products involved in the persistence:

  • Hibernate core: This annotation implements the JPA interface. It is one of the first persistence engines. This product is developed inside the JBoss community.

  • Hibernate Entity Manager: The interface for using the JPA through Hibernate. You will only see the standard API, and only in a few cases will you need to use the Hibernate implementation directly.

  • Hibernate Search: This lets you work with indexes. Indexes are an important feature of relational databases. Indexes are faster than queries. With this product, you obtain major performance boosts according to custom configurations of the indexes. It provides annotations to add to the data fields so that you can configure them to improve performance. It works together with Apache Lucene, the main Java index engine.

See now how JPA works in WildFly. In the next paragraphs we will focus on:

  • Descriptions of all JPA annotations and how to use them
  • Java connector architecture and DataSource
  • Available query types and relationship types
  • News in Java EE 7 about persistence
  • How to add the indexes to the tables and Java beans