Java Reference
In-Depth Information
Working with JPA
Inspired by ORM frameworks such as Hibernate, JPA uses annotations to map objects to a
relational database. JPA entities are POJOs that do not extend any class nor implement any
interface. You don't even need XML descriptors for your mapping. Actually, the JPA API is
made up of annotations and only a few classes and interfaces. For example, we will mark
the Company class as @Entity , shown as follows:
import javax.persistence.Entity;
import javax.persistence.Id;
public class Company {
// Some code
private String companyName;
public Company () { }
// Some code
The preceding piece of code shows the minimal requirements for a class to be persistent,
which are as follows:
• It must be identified as an entity using the @javax.persistence.Entity
• It must have an identifier attribute annotated with @javax.persistence.Id
• It must have a no-argument constructor in at least the protected scope
Since you will learn better with an example, we will show how to create and deploy a
sample JPA application in WildFly in the next section.
Search WWH ::

Custom Search