Wednesday, February 20, 2013

Add JPA/Hibernate to an existing eclipse Project


Add JPA/Hibernate Support:

Here we have an existing Eclipse Project, to wich we would like to add JPA/Hibernate support.

Open the project properties:

We can add more details by a simple clic on "Further configuration available. Here, we can add the connection to the database, we we have configured before ( see post Create JPA Project using JPA/Hibernate and MySQL Server  ) 

Resolve Console Configuration Error :

Here, a JPA Error appears : " Console Configuration "" does not exist. ".  In fact, a console configuration describes how the hibernate plugin should configure Hibernate and what configuration files and classpaths are needed to load the POJO's, JDBC Drivers...It is required to make use of query, reverse engineering and code generation.
To setup this Console Configuration,  we should go to the Hibernate Setting in the Project Properties.

Clic details to setup more details about the Console,

When trying to browse the persistence unit, I can't find my persistence.xml. In fact, according to Hibernate, this field is not required if my project have already /META-INF/persistence.xml in its classpath.

We can then see this configuration by opening the Hibernate Configurations View

So we can  see the different tables in the Database and even edit the created configuration.

Object-Relation Mapping- Entities Creation:

Once all is well settled, we can use the Hibernate Plugin to automatically cretae our entities. The mapping between Tables and Entities is then realized.

The entities are then created depending on tables available on our database. These entities (Java Classes, POJO) are created, they should be declared in the JPA Persistence Unit:

< class > fr.jpa.model.Vehicule </ class >

1 comment :

  1. This comment has been removed by a blog administrator.


Articles les plus consultés