Wednesday, February 20, 2013

Create JPA Project using JPA/Hibernate and MySQL Server

Removed

Database Creation in MySQL Server:


We begin by downloading the MySQL installer which includes MySQL server, the JDBC and MySQL Worbench.

So let's begin by creating the database in MySQL Server:

Then we use this database in order to create our tables.  We can create for example the table Vehicule.


Creation of the Database Connection in Eclipse:

To begin, we should create the connection with MySQL Server and especially with the database that we will work on it. So let's open the JPA perspective in Eclipse in order to configure our connection.

Window -> Open Perspective -> JPA




We create then a new Database Connection.


By choosing MySql Server, we will next add the different properties about our database.



 Here we should specify the path to our Driver. It can be downloaded using MySQL Installer or directly from MySQL connector page.



After that, we should change the informations by giving the database name, the URL and User/Password proporties. We can next try the connection to be sure that all is well settled.


In the Data Source Explorer, the database connection is then added and we can consult the database and their different tables, schemes...

JPA Project Creation:


The next steps consists on creating the JPA project. To do that, we can create it directly with eclipse.




We should add the Hibernate libraries downloaded before from their repository by selecting hibernate -> Add Jars:


We specify also the Connection that we have created and we would like to work with. We can also add the MySQL driver library by checking the box for that purpose.

The JPA project looks than like that where we can see the persistence.xml configuration file in src/META-INF, hibernate libraries and MySQL connector.



To add JPA/Hibernate capabilities to an existing project, please see the post "Add JPA/Hibernate to an existing eclipse Project".

Now that we have created our JPA project, we can enhance the persistence.xml file with more properties, and manage the Object-Relational Mapping by creating the entities from the database.

5 comments :

  1. First of all thank you for your tutorial. It is being really useful.

    I am writing you to ask for help. I am being promped with the warning "No connection specified for project. No database-specific validation will be performed" . Checking your Project Explorer, there is MySQL JDBC Driver library that isn't in mine. However, I downloaded the file and added it to my project but still not working. Please, Does anyone has any idea how I could troubleshoot it

    Thanks in advance,

    ReplyDelete
    Replies
    1. Hello, I wasn't available these days. It is nice that you have found the solution and happy that my tutorial helps you

      Delete
  2. Hi again,

    I found the solution. My problem was that I didn't select the database in the part "Connection" from the Configure JPA settings.

    ReplyDelete
  3. Generally I do not learn post on blogs, but I wish
    to say that this write-up very pressured me to take a look at and do so!
    Your writing style has been surprised me. Thanks, very nice post.


    My weblog Moukhtar Abliazov escroc

    ReplyDelete
  4. This comment has been removed by a blog administrator.

    ReplyDelete

Articles les plus consultés