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:
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:
To maintain the JPA coherence we must add an Identifier on every classes, Registry has one, but we must add one to SchoolCertificates:
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.