Java Reference
In-Depth Information
Software developers knew what they wanted, but many could not find it in the exist-
ing standards, so they decided to look elsewhere. What they found was proprietary
persistence frameworks, both in the commercial and open source domains.
In contrast to EJB 2.x Entity Beans, the EJB 3.0 Java Persistence API ( JPA ) is a
metadata driven POJO technology. That is, to save data held in Java objects into a
database, our objects are not required to implement an interface, extend a class, or
fit into a framework pattern.
Another key feature of JPA is the query language, called the Java Persistence
Query Language ( JPQL ), which gives you a way to specify the semantics of queries
in a portable way, independent of the particular database you are using in an enter-
prise environment. JPA queries resemble SQL queries by syntax but operate against
entity objects rather than directly with database tables.
Working with JPA
Inspired by ORM frameworks such as Hibernate, JPA uses annotations to map ob-
jects 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 inter-
faces. For example, we would mark the class Company as @Entity as follows:
@Entity
public class Company {
...
public Company () { }
@Id
String companyName;
...
}
This little piece of code shows the minimal requirements for a class to be persistent.
That is:
Search WWH ::




Custom Search