EclipseLink JPA With MySQL

EclipseLink JPA With MySQL explains step by step details of setting / configuring Java Persistence (JPA) With EclipseLink And MySQL

How To Configure EclipseLink (JPA) With MySQL Database?

Java Persistence API (JPA), is a standard interface which wraps different ORM tools such as  Hibernate, EclipseLink, OpenJPA etc.

ie; you can able to change Hibernate implementation to EclipseLink implementation without changing the code base.

On this standalone JPA Example, we are using EclipseLink With MySQL Database

If you want to configure EclipseLink (JPA) With Oracle Database, you can follow Configure EclipseLink (JPA) With Oracle Database

EclipseLink is popular open source ORM (Object Relation Mapping) tool for Java platform, for mapping an entity to a traditional relational database like Oracle, MySQL etc

I am going to re-use my JPA Tutorial With EclipseLink


You need to remove classes12.jar (Oracle driver) and add mysql-connector-java-5.1.18-bin.jar (MySQL driver) into classpath

You can check below different database with Hibernate and EclipseLink examples

Database Driver class Jar name Examples
MySQL com.mysql.jdbc.Driver mysql-connector-java-5.1.25-bin.jar (exact name depends on version)
EclipseLink JPA With MySql
Hibernate JPA With MySql
HSQLDB org.hsqldb.jdbcDriver hsqldb.jar
Hibernate JPA With HSQL
EclipseLink JPA With HSQL
Sybase com.sybase.jdbc3.jdbc.SybDriver jconnect.jar
Hibernate JPA With Sybase
EclipseLink JPA With Sybase
Apache Derby org.apache.derby.jdbc.EmbeddedDriver derby.jar
Hibernate JPA With Derby
EclipseLink JPA With Derby
IBM DB2 db2jcc4.jar
Hibernate JPA With DB2
EclipseLink JPA With DB2
PostgreSQL org.postgresql.Driver postgresql-8.4-701.jdbc4.jar (exact name depends on PostgreSQL version)
Hibernate JPA With PostgreSQL
EclipseLink JPA With PostgreSQL
SQL Server (Microsoft driver) sqljdbc4.jar
Hibernate JPA With SQL Server
EclipseLink JPA With SQL Server
Informix com.informix.jdbc.IfxDriver ifxjdbc.jar
Hibernate JPA With Informix
EclipseLink JPA With Informix
H2 org.h2.Driver h2.jar
Hibernate JPA With H2
EclipseLink JPA With H2

Modify persistence.xml

persistence.xml file must be under src/META-INF (Please check below screenshot(project structure)

<persistence xmlns:xsi=""
  version="2.0" xmlns="">
  <persistence-unit name="test" transaction-type="RESOURCE_LOCAL">
      <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" />
      <property name="javax.persistence.jdbc.url"    value="jdbc:mysql://localhost/test" />
      <property name="javax.persistence.jdbc.user" value="username" />
      <property name="javax.persistence.jdbc.password" value="password" />
      <property name="eclipselink.ddl-generation" value="create-tables" />
      <property name="eclipselink.ddl-generation.output-mode" value="database" />

Package Structure

Now package structure looks like following

Configure EclipseLink (JPA) With MySql Database Structure

1 2 Next

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