JPA: persistence with EclipseLink

Today we will see how to make the persistence in a Eclipse project with EclipseLink JPA implementation.

We will base in the last post Eclipse project. In the project properties (right buton) we will add the power to manage JPA entities, adding the facet:

Adding JPA facet

We will ue EclipseLink 1.1.2, it is the JPA implementation by defect in WebLogic 11g.

Generating entities from tables

Over the project, in the contextual menu (right button), JPA > Generate Entities from Tables… We choose the conection SCHOOL, created in other posts, and tables REGISTRY and SCHOOLCERTIFICATES. Generating the entities in the package lebrijo.school.model:

Generating entities from tables

To maintain the JPA coherence we must add an Identifier on every classes, Registry has one, but we must add one to SchoolCertificates:

Add Identifier

You may see the file src/META-INF/persistence.xml, how it configures the connection and map the entities.

<persistence version="1.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_1_0.xsd">
<persistence-unit name="school" transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
 	<class>lebrijo.school.model.Registry</class>
 
 	<class>lebrijo.school.model.Schoolcertificate</class>
		<properties>
			<property name="eclipselink.target-server" value="WebLogic_10"/>
			<property name="eclipselink.jdbc.driver" value="oracle.jdbc.OracleDriver"/>
			<property name="eclipselink.jdbc.url" value="jdbc:oracle:thin:@192.168.0.7:1521:xe"/>
			<property name="eclipselink.jdbc.user" value="school"/>
			<property name="eclipselink.jdbc.password" value="school"/>
			<property name="eclipselink.logging.level" value="FINEST"/>
		</properties>
 </persistence-unit>
</persistence>

here I leaveth eclipse zip project after these steps.

One thought on “JPA: persistence with EclipseLink

  1. Hi Neal,Storing relationship state is a bit more diuifcflt in the Java object world (as compared to the Database relational world). Just providing the simple ManyToMany relationship between Student and Course is relatively straight forward. But, when you throw in the extra attribute state (start and end dates), then it gets more diuifcflt.The most common solution is to turn the relationship into an Entity. This new Entity would provide both the desired state attributes as well as the relationship data (replacing the standard join table). This new Entity will have a ManyToOne relationship to the existing Entity types. And, each of these existing Entity types would have a OneToMany relationship with the new Entity type.The primary key of this new Entity (relationship) would be a combination of the keys for the existing Entity types.A good example of this can be found in Chapter 8 of the Pro EJB 3, Java Persistence API book by Mike Keith and Merrick Schincariol.Hope this helps,Kevin

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>