Hello, In this article we will learn how to create a jpa project in eclipse.
What do we need?
For setting up JPA project, we are using
- mysql database 5.x
- eclipse kepler
- JPA 2.x
- Some database created in your mysql database. I have created a database named thejavageek.
That’s all we need to create a jpa project in eclipse.
Open your eclipse workspace and then File > New > JPA Project . You will see a dialogue as follows.
Name your project as JPAExamples and select appropriate JPA version. I’ve selected JPA 2.1. Keep clicking next till you see this dialogue.
This dialogue provides information about available jpa libraries in workspace. If they are not available there, you can download corresponding libraries from the option provided.
I’ve selected eclipseLink version 2.5 here. Now create a database connection using Add Connection link.
I’ve selected MySQL here as its the database server I’m using. Click next till you get this dialogue.
Fill in your database details here, For me database url : jdbc:mysql://localhost:3306/thejavageek .
That’t it. You can test the connection now. It will succeed and click Finish on the dialogue box.
You have learned how to create a jpa project in eclipse. You can see a file called persistence.xml created in your project.
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">