Tuesday, February 25, 2014

Resolve [Classpath]: Could not create JPA based Configuration and Invalid persistence xml Errors in Eclipse JBoss eap 6.2

Removed
The problem is that when I have created the persistence.xml, I was using JPA2.1. JBoss Eap 6.2 comes with JPA2.0, I am also using JBoss Tools. So I have two problems

by: javax.persistence.PersistenceException: Invalid persistence.xml.
Error parsing XML (line-1 : column -1): cvc-elt.1: Cannot find the declaration of element 'persistence'.

and 

[Classpath]: Could not create JPA based Configuration






Solution:  You should not use JPA2.1 but instead use JPA 2.0 as JBoss comes with this latest version. So in the persistence.xml use this declaration.

persistence version="2.0" 
xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"

Now my persistence.xml is working and I can see my tables in the Hibernate View.


And Here my Hibernate console:

Don't forget to specify the Database connection with the right JDBC. after this, you can see your tables. And thus generate your entities.

Right clic on the project --> JPA tools --> Generate Entities from Tables, and Specify the Hibernate Console.


The entities will be correctly generated.


3 comments :

Articles les plus consultés