Java Reference
In-Depth Information
JPA in action
JPA is based on the concept of entities, in order to make object-relational mapping
possible. An entity is a simple Java class (like POJO ) with @Entity annotation (or
XMLequivalent)whosenameisbydefaultassociatedwiththetablehavingthesame
name in the database. In addition to the @Entity annotation, an entity class must
have at least one primary key equivalent attribute that is designated with the @Id
annotation (or XML equivalent). For the other attributes of the entity, the provider as-
sociates each of them to the column having the same name in the table, as shown
in the following screenshot:
The parameters that indicate the database that will be associated to a set of entities
must be defined in the persistence unit within the persistence.xml file of your
application.
The following code is an example of the persistence unit of a Java SE Application:
<?xml version="1.0" encoding="UTF-8"?>
<persistence
version="2.1"xmlns="http://xmlns.jcp.org/xml/ns/
persistence"
xmlns:xsi="http://www.w3.org/2001/
XMLSchema-instance"
Search WWH ::




Custom Search