2‐Exemple
Etape2créationdel'entitédepersistance
packagejpa;
importjavax.persistence.*;
@Entity
publicclassClientimplements Serializable {
@Id
private Longid;
private Stringprenom;
private Stringnom;
private StringdateNaissance;
private StringdateCreation;
private int age;
private Stringemail;
private Adresseadresse;
//méthodesget etset}
packagejpa;
importjavax.persistence.*;
@Entity
publicclassClientimplements Serializable {
@Id
private Longid;
private Stringprenom;
private Stringnom;
private StringdateNaissance;
private StringdateCreation;
private int age;
private Stringemail;
private Adresseadresse;
//méthodesget etset}
Etape1Mise enplacedel'unitédepersistancedanslefichierMETA‐INF/persistence.xml
<?xml version="1.0"encoding="UTF‐8"?>
<persistence version="2.0"xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema‐instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence‐unit name="jpa1"transaction‐type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<class>jpa.Client</class>
<properties>
<property name="javax.persistence.jdbc.url"value="jdbc:derby://localhost:1527/bdJpa"/>
<property name="javax.persistence.jdbc.password"value="jpa"/>
<property name="javax.persistence.jdbc.driver"
value="org.apache.derby.jdbc.ClientDriver"/>
<property name="javax.persistence.jdbc.user"value="jpa"/>
<property name="eclipselink.ddl‐generation"value="create‐tables"/>
</properties>
</persistence‐unit>
</persistence>
<?xml version="1.0"encoding="UTF‐8"?>
<persistence version="2.0"xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema‐instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence‐unit name="jpa1"transaction‐type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<class>jpa.Client</class>
<properties>
<property name="javax.persistence.jdbc.url"value="jdbc:derby://localhost:1527/bdJpa"/>
<property name="javax.persistence.jdbc.password"value="jpa"/>
<property name="javax.persistence.jdbc.driver"
value="org.apache.derby.jdbc.ClientDriver"/>
<property name="javax.persistence.jdbc.user"value="jpa"/>
<property name="eclipselink.ddl‐generation"value="create‐tables"/>
</properties>
</persistence‐unit>
</persistence>