Configuring JPA

We are going to use the EclipseLink JPA provider and the MySQL database driver in this project. So, add the Maven dependencies for them in the pom.xml file of the project:

  <!-- JPA --> 
  <dependency> 
        <groupId>org.eclipse.persistence</groupId> 
        <artifactId>eclipselink</artifactId> 
        <version>2.7.1</version> 
      </dependency> 
      <dependency> 
        <groupId>mysql</groupId> 
        <artifactId>mysql-connector-java</artifactId> 
        <version>8.0.9-rc</version> 
  </dependency> 

We will now configure the project for JPA. Right-click on the project and select Configure | Convert to JPA Project. This opens the Project Facets page, with JPA selected as one of the facets:


Figure 8.5: Project facets

Click the Next button to configure the JPA facet:

Figure 8.6: JPA facet

Select the EclipseLink platform in the preceding page. We will also disable the library configuration (select from the dropdown for the Type field). Configure the MySQL Connection (named CourseMgmtDBConnection), as described in the Configuring JPA section of Chapter 7, Creating JEE Applications with EJB.

Click Finish. Persistence.xml is created under the JPA Content group in Project Explorer (the actual location of this file is src/main/resources/META-INF/persistence.xml). We will configure properties for the MySQL JDBC connection in this. Open the file and click the Connection tab:

Figure 8.7: Configure connection in persistence.xml

Select Transaction type as Resource Local. Then, enter the JDBC driver details. Save the file.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.12.136.186