views:

149

answers:

2

I am new to JPA & hibernate. In my web-app i have changed my JDBC codes to JPA. While running the web-app i am getting a BIG list of errors. But from my knowledge in JPA and Hibernate, I think the two errors below represent most of my problem.

  • Unable to configure EntityManagerFactory
  • 16047 [31149935@qtp-23671010-1] ERROR org.hibernate.util.XMLHelper - Error parsing XML: XML InputStream(2) cvc-complex-type.3.1: Value '2.0' of attribute 'version' of element 'entity-mappings' is not valid with respect to the corresponding attribute use. Attribute 'version' has a fixed value of '1.0'.

I have searched a lot for these errors on the web. But I can't find one solution. I have included all the required JARs and added persistence.xml to the class path. I am not able to find the reason.

Here my full list of console errors:

SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/C:/Documents%20and%20Settings/tamilvendhank/Local%20Settings/Temp/Jetty_127_0_0_    1_8080_ExpMgmtWeb.war__ExpMgmtWeb__w96xvk_3923622842201679764/webapp/WEB-INF/lib/slf4j-log4j12.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/C:/Documents%20and%20Settings/tamilvendhank/Local%20Settings/Temp/Jetty_127_0_0_1_8080_ExpMgmtWeb.war__ExpMgmtWeb__w96xvk_3923622842201679764/webapp/WEB-INF/lib/slf4j-simple-1.5.11.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
15360 [31149935@qtp-23671010-1] INFO  org.hibernate.cfg.annotations.Version  -    Hibernate Annotations 3.4.0.CR1
15375 [31149935@qtp-23671010-1] INFO  org.hibernate.cfg.Environment  - Hibernate 3.3.0.CR1
15375 [31149935@qtp-23671010-1] INFO  org.hibernate.cfg.Environment  - hibernate.properties not found
15375 [31149935@qtp-23671010-1] INFO  org.hibernate.cfg.Environment  - Bytecode provider name : cglib
15375 [31149935@qtp-23671010-1] INFO  org.hibernate.cfg.Environment  - using JDK 1.4 java.sql.Timestamp handling
15469 [31149935@qtp-23671010-1] INFO  org.hibernate.annotations.common.Version  - Hibernate Commons Annotations 3.1.0.CR1
15469 [31149935@qtp-23671010-1] INFO  org.hibernate.ejb.Version  - Hibernate EntityManager 3.4.0.CR1
16047 [31149935@qtp-23671010-1] ERROR org.hibernate.util.XMLHelper  - Error parsing XML: XML InputStream(2) cvc-complex-type.3.1: Value '2.0' of attribute 'version' of element 'entity-mappings' is not valid with respect to the corresponding attribute use. Attribute 'version' has a fixed value of '1.0'.
2010-09-19 11:23:40.265:WARN::Error for /ExpMgmtWeb/dwr/call/plaincall/ExpenseDetailsManagement.getexpenseList.dwr
java.lang.ExceptionInInitializerError
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at java.lang.Class.newInstance0(Unknown Source)
at java.lang.Class.newInstance(Unknown Source)
at org.directwebremoting.create.NewCreator.getInstance(NewCreator.java:66)
at org.directwebremoting.impl.DefaultRemoter.execute(DefaultRemoter.java:344)
at org.directwebremoting.impl.DefaultRemoter.execute(DefaultRemoter.java:279)
at org.directwebremoting.servlet.PlainCallHandler.handle(PlainCallHandler.java:52)
at org.directwebremoting.servlet.UrlProcessor.handle(UrlProcessor.java:101)
at org.directwebremoting.servlet.DwrServlet.doPost(DwrServlet.java:144)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511)
at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:390)
at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)
at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765)
at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:418)
at org.mortbay.jetty.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:230)
at org.mortbay.jetty.handler.HandlerCollection.handle(HandlerCollection.java:114)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
at org.mortbay.jetty.Server.handle(Server.java:326)
at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)
at org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:943)
at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:756)
at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:212)
at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:410)
at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582)
2010-09-19 11:23:40.265:WARN::Nested in java.lang.ExceptionInInitializerError:
javax.persistence.PersistenceException: [PersistenceUnit: ExpensePersistentUnit] Unable to configure EntityManagerFactory
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:265)
at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:125)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:51)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:33)
at com.pricar.JPAInteg.ExpenseDetailsManagement.<clinit>(ExpenseDetailsManagement.java:21)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at java.lang.Class.newInstance0(Unknown Source)
at java.lang.Class.newInstance(Unknown Source)
at org.directwebremoting.create.NewCreator.getInstance(NewCreator.java:66)
at org.directwebremoting.impl.DefaultRemoter.execute(DefaultRemoter.java:344)
at org.directwebremoting.impl.DefaultRemoter.execute(DefaultRemoter.java:279)
at org.directwebremoting.servlet.PlainCallHandler.handle(PlainCallHandler.java:52)
at org.directwebremoting.servlet.UrlProcessor.handle(UrlProcessor.java:101)
at org.directwebremoting.servlet.DwrServlet.doPost(DwrServlet.java:144)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511)
at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:390)
at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)
at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765)
at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:418)
at org.mortbay.jetty.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:230)
at org.mortbay.jetty.handler.HandlerCollection.handle(HandlerCollection.java:114)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
at org.mortbay.jetty.Server.handle(Server.java:326)
at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)
at org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:943)
at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:756)
at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:212)
at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:410)
at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582)

alt text

 <?xml version="1.0" encoding="UTF-8"?>
 <persistence>
<persistence-unit name="ExpensePersistentUnit">
 <provider>org.hibernate.ejb.HibernatePersistence</provider>
    <class>com.pricar.JPAInteg.Role</class>
    <class>com.pricar.JPAInteg.User</class>
    <class>com.pricar.JPAInteg.Userdetail</class>
    <class>com.pricar.JPAInteg.Category</class>
    <class>com.pricar.JPAInteg.Expens</class>
    <class>com.pricar.JPAInteg.Leavetable</class>
    <class>com.pricar.JPAInteg.Permissiontoken</class>
    <class>com.pricar.JPAInteg.Roletokenassociation</class>
    <class>com.pricar.JPAInteg.UserPK</class>
 <properties>
    <property name="hibernate.connection.url" value="jdbc:mysql://localhost/officemgmt"/>
    <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"></property>
    <property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/>
    <property name="hibernate.connection.password" value="1234"/>
    <property name="hibernate.connection.username" value="root"/>
    <property name="hibernate.hbm2ddl.auto" value="update"/>
    <property name="hibernate.show_sql" value="true"/>
 </properties>
 </persistence-unit> 
 </persistence>

Update:

javax.persistence.PersistenceException: [PersistenceUnit: ExpensePersistentUnit] Unable to configure EntityManagerFactory
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:371)
at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:55)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:51)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:33)
at com.pricar.JPAInteg.ExpenseDetailsManagement.<clinit>(ExpenseDetailsManagement.java:21)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at java.lang.Class.newInstance0(Unknown Source)
at java.lang.Class.newInstance(Unknown Source)

Update 2:

I have some basic questions:

  1. How many xml files involved in JPA+Hibernate combination, if JPA annotations were used? i am having just persistence.xml. But totally 3(dwr.xml & web.xml)

  2. Is hibernate.cfg.xml needed, if i use JPA annotaions. Because, i didnt added it till now.

  3. Shall you give me the list of basic JAR file names, in case of using JPA 2.0 & Hibernate!!! Because, i am having more than 15 files.

A: 

16047 [31149935@qtp-23671010-1] ERROR org.hibernate.util.XMLHelper - Error parsing XML: XML InputStream(2) cvc-complex-type.3.1: Value '2.0' of attribute 'version' of element 'entity-mappings' is not valid with respect to the corresponding attribute use. Attribute 'version' has a fixed value of '1.0'.

Looks like this is error in your xml with some kind of attribute version's value.

Jaydeep
@pascal's answer may I know why my answer is down voted. He also pointed the same thing (XML)
Jaydeep
@jaydeep: I actually got frustrated from your answer. I know that the problem was with the xml files. But i cant clear them, and thats why i asked help here. And, what you did. Just pasted the lines from my question and pointing the same thing i already know, and dont know to get out of it.Ok, Cool... I tried to up vote again. But it ll be updated after you edit your answer.
NooBDevelopeR
+2  A: 

You are using a JPA 1.0 implementation, you need to provide a JPA 1.0 compliant orm.xml (note the version attribute amongst other things):

<?xml version="1.0" encoding="UTF-8"?>
<entity-mappings 
  xmlns="http://java.sun.com/xml/ns/persistence/orm"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm http://java.sun.com/xml/ns/persistence/orm_1_0.xsd"
  version="1.0">
  ...
</entity-mappings>

Yours probably looks like:

<?xml version="1.0" encoding="UTF-8"?>
<entity-mappings
  xmlns="http://java.sun.com/xml/ns/persistence/orm"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm http://java.sun.com/xml/ns/persistence/orm_2_0.xsd"
  version="2.0">
  ...
</entity-mappings>

Which is correct... if you are using a JPA 2.0 provider.

But to be honest, I don't know why you are providing an orm.xml, you usually don't need an XML mapping file when using annotations.

References

  • JPA 1.0 Specifciation
    • Section "10.2 XML Schema"
  • JPA 2.0 Specifciation
    • Section "12.3 XML Schema"

Thanks for your reply and sorry for the orm.xml. My intense is to show the location of persistence.xml. I am not using XML mapping. That orm.xml is auto generated. Shall I remove that file?

I would try to remove the orm.xml indeed, entity-mappings is the root element of the orm.xml, that's what the error is about.

What do you mean in "if you are using a JPA 2.0 provider"? Provider means, Hibernate??

JPA is just an API. To use JPA, you need an implementation of this API and such implementations are called persistence providers (EcliseLink, Hibernate, OpenJPA). In your case, you are using Hibernate EntityManager 3.4.0.GA which is a JPA 1.0 implementation.

What I have to do to change to JPA 2.0? by adding javax.persistence_2.0.0.jar or by change the hibernate which is using JPA 2.0??

Both, you'd have to use Hibernate EntityManager 3.5+ (and its dependencies, and this includes the javax.persistence_2.0.0.jar).

Pascal Thivent
@pascal: Thanks for your reply and sorry for the orm.xml.. My intense is to show the location of persistence.xml. I am not using XML mapping. That orm.xml is auto generated. Shall i remove that file? What do you mean in "if you are using a JPA 2.0 provider"? Provider means, Hibernate?? What i have to do to change to JPA 2.0? by adding javax.persistence_2.0.0.jar or by change the hibernate which is using JPA 2.0??
NooBDevelopeR
@Pascal: I have added persistence.xml file in my question. My orm.xml file is empty.
NooBDevelopeR
NooBDevelopeR
@Pascal: I have updated the new errors in my Question
NooBDevelopeR