Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

javax.persistence.PersistenceException: Unable to locate persistence units

 
David Freed
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I had a Maven project, I converted it to JPA project which now works with Maven. My persistence.xml is as follows:



And I have the following Entities:



And this is where the error occures:



Now the error: javax.persistence.PersistenceException: Unable to locate persistence units


Picked up JAVA_TOOL_OPTIONS: -javaagent:/usr/share/java/jayatanaag.jar
log4j:WARN No appenders could be found for logger (twitter4j.HttpClientImpl).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
Exception in thread "Thread-1" javax.persistence.PersistenceException: Unable to locate persistence units
at org.hibernate.jpa.HibernatePersistenceProvider.getEntityManagerFactoryBuilderOrNull(HibernatePersistenceProvider.java:101)
at org.hibernate.jpa.HibernatePersistenceProvider.getEntityManagerFactoryBuilderOrNull(HibernatePersistenceProvider.java:88)
at org.hibernate.jpa.HibernatePersistenceProvider.createEntityManagerFactory(HibernatePersistenceProvider.java:69)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:79)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:54)
at model.TweetPersistent.insertToDB(TweetPersistent.java:32)
at model.TweetPersistent.persist(TweetPersistent.java:24)
at controller.TwitterStreamConsumer.run(TwitterStreamConsumer.java:25)
at java.lang.Thread.run(Thread.java:745)
Caused by: javax.persistence.PersistenceException: Invalid persistence.xml.
Error parsing XML [line : -1, column : -1] : cvc-elt.1: Deklaration des Elements "persistence" kann nicht gefunden werden.
at org.hibernate.jpa.boot.internal.PersistenceXmlParser.validate(PersistenceXmlParser.java:377)
at org.hibernate.jpa.boot.internal.PersistenceXmlParser.loadUrl(PersistenceXmlParser.java:310)
at org.hibernate.jpa.boot.internal.PersistenceXmlParser.parsePersistenceXml(PersistenceXmlParser.java:114)
at org.hibernate.jpa.boot.internal.PersistenceXmlParser.doResolve(PersistenceXmlParser.java:104)
at org.hibernate.jpa.boot.internal.PersistenceXmlParser.locatePersistenceUnits(PersistenceXmlParser.java:86)
at org.hibernate.jpa.HibernatePersistenceProvider.getEntityManagerFactoryBuilderOrNull(HibernatePersistenceProvider.java:97)
... 8 more

I included different jars: hibernate-validation,java-persistence,hibernate-jpa and hibernate-entityManager in the build path and also class path of project itself. I also copied persistence.xml in resource folder.
I did lots of things but it does not work, always the same error.

Thank you in advance for your suggestions.

 
Roel De Nijs
Sheriff
Posts: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
David Freed wrote:I did lots of things but it does not work, always the same error.

Did you already try using another persistence tag? According to the official JPA 2.1 xsd (starting from line 50) the persistence tag must beThat's slightly different from the one you are using.
 
Roel De Nijs
Sheriff
Posts: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And if you want JPA 2.0 it should beSeems you use a mix of JPA 2.0 and JPA 2.1 notation.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic