Agenda:
1. Creating JPA project and generating entities.
2. Configuring persistence properties and JPA project
3. Testing the JPA project
1. Creating JPA project and generating entities.
2. Configuring persistence properties and JPA project
3. Testing the JPA project
This post shows how to configure the JPA project about its' persistence properties after entities successfully generated in a JPA project.
Before we start to configure our JPA project, first we must decide which JPA implementation to use.
There are two(2) popular JPA implementations, which are EclipseLink and Hibernate.
Once the preferred JPA implementation installed, then we can start to configure the persistence properties.
Steps:
b) unzip the archive
c) copy the javax.persistence_2.0.4.v201112161009.jar and eclipselink.jar to a folder (eg, c:\eclipselink-lib)
d) create a user libraries name eclipselink in eclipse, and add all above jar into this user library.
e) create a user libraries for the target jdbc driver, and add the jdbc jar into this user library
f) add these 2 user libraries to the JPA project.
a) download the required Hibernate Library, and the version that I used in this tutorial is 4.2.0
b) unzip the archive
c) copy the jar files below to a folder (eg, c:\eclipselink-lib\hibernate)
- antlr-2.7.7.jar
- dom4j-1.6.1.jar
- hibernate-commons-annotations-4.0.1.Finall.jar
- hibernate-core-4.2.0.Final.jar
- hibernate-entitymanager-4.2.0.Final.jar
- hibernate-jpa-2.0-api-1.0.1.Final.jar
- javassist-3.15.0-GA.jar
- jboss-logging-3.1.0.GA.jar
- jboss-transaction-api_1.1_spec-1.0.0.Final.jar
d) create a user libraries name hibernate in eclipse, and add all above jar into this user library.
e) create a user libraries for the target jdbc driver, and add the jdbc jar into this user library
f) add these 2 user libraries to the JPA project.
at this stage, all the Eclipse compilation errors should be gone.
b) in General tab, fill in Persistence provider by your choice of JPA implementation.
c) in Connection tab, choose Resource Local for Transaction type
d) Fill in Driver, URL, User, Password or Populate from connection... to choose a configured database connection
e) save persistence.xml
Done!!
Before we start to configure our JPA project, first we must decide which JPA implementation to use.
There are two(2) popular JPA implementations, which are EclipseLink and Hibernate.
Once the preferred JPA implementation installed, then we can start to configure the persistence properties.
Steps:
1. Install JPA implementation library
1.1 EclipseLink
a) download the required EclipseLink library, and the version that I used in this tutorial is 2.4.1b) unzip the archive
c) copy the javax.persistence_2.0.4.v201112161009.jar and eclipselink.jar to a folder (eg, c:\eclipselink-lib)
d) create a user libraries name eclipselink in eclipse, and add all above jar into this user library.
e) create a user libraries for the target jdbc driver, and add the jdbc jar into this user library
f) add these 2 user libraries to the JPA project.
1.2 Hibernate
a) download the required Hibernate Library, and the version that I used in this tutorial is 4.2.0
b) unzip the archive
c) copy the jar files below to a folder (eg, c:\eclipselink-lib\hibernate)
- antlr-2.7.7.jar
- dom4j-1.6.1.jar
- hibernate-commons-annotations-4.0.1.Finall.jar
- hibernate-core-4.2.0.Final.jar
- hibernate-entitymanager-4.2.0.Final.jar
- hibernate-jpa-2.0-api-1.0.1.Final.jar
- javassist-3.15.0-GA.jar
- jboss-logging-3.1.0.GA.jar
- jboss-transaction-api_1.1_spec-1.0.0.Final.jar
d) create a user libraries name hibernate in eclipse, and add all above jar into this user library.
e) create a user libraries for the target jdbc driver, and add the jdbc jar into this user library
f) add these 2 user libraries to the JPA project.
at this stage, all the Eclipse compilation errors should be gone.
2. configure persistence properties in persistence.xml.
a) d-click to open persistence.xml in <JPA_Project>/src/META-INFb) in General tab, fill in Persistence provider by your choice of JPA implementation.
EclipseLink | org.eclipse.persistence.jpa.PersistenceProvider |
Hibernte | org.hibernate.ejb.HibernatePersistence |
c) in Connection tab, choose Resource Local for Transaction type
d) Fill in Driver, URL, User, Password or Populate from connection... to choose a configured database connection
e) save persistence.xml
PREV Generating Entities | Testing the JPA project NEXT |
Done!!
No comments:
Post a Comment