-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 
Author Message
 Post subject: Can't find hibernate-configuration-3.0.dtd
PostPosted: Tue Jun 02, 2009 10:32 am 
Newbie

Joined: Wed Feb 18, 2009 4:26 am
Posts: 7
Hi all,

I'm getting a problem with the declaration of the DTD in the hibernate files (hibernate.cfg.xml as well as *.hbm.xml).
The problem appeared while using hibernate in a web application project, in debug, under Eclipse and with a tomcat 6.0 server.
There is no problems while testing each module with JUnit.

The problems seems to be that hibernate does not find the "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd" ... It searches in the classpath but can't find it ... Normal!

Here is the stack trace :

Code:
2009-06-02 14:59:29,406 DEBUG [AccessFactory] Création de la SessionFactory à partir du fichier de configuration hibernate.cfg.xml
2009-06-02 14:59:29,484 INFO  [Environment] Hibernate 3.3.1.GA
2009-06-02 14:59:29,484 INFO  [Environment] loaded properties from resource hibernate.properties: {hibernate.bytecode.use_reflection_optimizer=false}
2009-06-02 14:59:29,484 INFO  [Environment] Bytecode provider name : javassist
2009-06-02 14:59:29,500 INFO  [Environment] using JDK 1.4 java.sql.Timestamp handling
2009-06-02 14:59:29,562 INFO  [Configuration] configuring from resource: hibernate.cfg.xml
2009-06-02 14:59:29,562 INFO  [Configuration] Configuration resource: hibernate.cfg.xml
2009-06-02 14:59:29,609 DEBUG [DTDEntityResolver] trying to resolve system-id [http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd]
2009-06-02 14:59:29,609 DEBUG [DTDEntityResolver] recognized hibernate namespace; attempting to resolve on classpath under org/hibernate/
2009-06-02 14:59:29,625 ERROR [AccessFactory] Erreur lors de la création de la SessionFactory.
2009-06-02 14:59:29,625 ERROR [PowerForumBS] Erreur lors de la configuration de l'accès à la base
fr.sporevo.socle.exception.database.DBAccessConfigurationException: Erreur de configuration de l'accès à la base
[...]
   at fr.sporevo.web.power.controller.forum.PowerControllerForum.doGet(PowerControllerForum.java:50)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
   at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
   at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
   at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
   at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
   at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
   at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
   at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)
   at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
   at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
   at java.lang.Thread.run(Unknown Source)
java.lang.ExceptionInInitializerError
   at fr.sporevo.socle.access.AccessFactory.<clinit>(AccessFactory.java:28)
[...]
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
   at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
   at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
   at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
   at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
   at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
   at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
   at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)
   at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
   at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
   at java.lang.Thread.run(Unknown Source)
Caused by: org.hibernate.HibernateException: Could not parse configuration: hibernate.cfg.xml
   at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1528)
   at org.hibernate.cfg.Configuration.configure(Configuration.java:1462)
   at fr.sporevo.socle.access.AccessFactory.<clinit>(AccessFactory.java:25)
   ... 18 more
Caused by: org.dom4j.DocumentException: null Nested exception: null
   at org.dom4j.io.SAXReader.read(SAXReader.java:484)
   at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1518)
   ... 20 more


Here is the code of the AccessFactory.java :
Code:
public class AccessFactory {

   private final static SessionFactory sessionFactory;
   
   // Logger
   private final static ILogger LOG = LoggerFactory.getLogger(AccessFactory.class);

   static {
      try {
         LOG.debug("Création de la SessionFactory à partir du fichier de configuration hibernate.cfg.xml");
         sessionFactory = new Configuration().configure("hibernate.cfg.xml").buildSessionFactory();
      } catch (Throwable ex) {
         LOG.error("Erreur lors de la création de la SessionFactory.");
         throw new ExceptionInInitializerError(ex);
      }
   }

   public static SessionFactory getSessionFactory() {
      return sessionFactory;
   }

   public static SessionFactory getSessionFactory(String hibernateConfigFile) {
      
      return sessionFactory;
   }

}

... Nothing so strange!

... I can't understand why it is working in debug with JUnit but not in a web application project!
Libraries & classpath seems the sames thought...

Any idea ?
Peterpan

_________________
--
www.sporevo.com


Top
 Profile  
 
 Post subject: Re: Can't find hibernate-configuration-3.0.dtd
PostPosted: Tue Jun 02, 2009 12:38 pm 
Newbie

Joined: Wed Feb 18, 2009 4:26 am
Posts: 7
Ok, After a few debug, it realy seems the DTDEntityResolver class has a problem somehow...

Here it is :
When configuring hibernate (new Configuration().configure("hibernate.cfg.xml")), hibernate start to read the 'hibernate.cfg.xml' file using the xerces XML Parser...
When reading the file, the resolveEntity function of class DTDEntityResolver is called.
It then calls resolveInHibernateNamespace at line 68 of DTDEntityResolver.java and does somethings whether the return is null or not.

But at line 104 of the DTDEntityResolver.java :
Code:
   protected InputStream resolveInHibernateNamespace(String path) {
      return this.getClass().getClassLoader().getResourceAsStream( path );
   }

When I evaluate the "this.getClass().getClassLoader()" in debug, it returns null !?!! What does it means ?!?
I think this call to getClassLoader should be protected as it is said in the documentation that
Quote:
Some implementations may use null to represent the bootstrap class loader. This method will return null in such implementations if this class was loaded by the bootstrap class loader.
[...]If this object represents a primitive type or void, null is returned.
...
So sometimes, it could return "null" ... and the call to getResourceAsStream should not like it!

Anyway, in our case, I dont understand why this.getClass().getClassLoader() returns null has this.getClass() returns "class org.hibernate.util.DTDEntityResolver" which normally has been loaded by the XMLHelper class at instanciation.
So why does the getClassLoader() return null ???

Someone ?

Anyway, getting back to the resolveInHibernateNamespace function, it should check the return of "this.getClass()" and "this.getClass().getClassLoader()", no ?
Maybe an old bug ? See http://opensource.atlassian.com/projects/hibernate/browse/HB-1370

_________________
--
www.sporevo.com


Top
 Profile  
 
 Post subject: Re: Can't find hibernate-configuration-3.0.dtd
PostPosted: Tue Jun 02, 2009 3:24 pm 
Newbie

Joined: Wed Feb 18, 2009 4:26 am
Posts: 7
Ok, it seams to be a problem between my hibernate version and Jdk 1.6 ...
Java now requires to use a SchemaFactory for validating an XSD ..
See https://jira.jboss.org/jira/browse/JBSEAM-2938 ...
Maybe that's what cause the bug ...
Someone to check that ?

_________________
--
www.sporevo.com


Top
 Profile  
 
 Post subject: Re: Can't find hibernate-configuration-3.0.dtd
PostPosted: Tue Jun 02, 2009 3:25 pm 
Newbie

Joined: Wed Feb 18, 2009 4:26 am
Posts: 7
Maybe the solution is to code my own DTD validator ?

_________________
--
www.sporevo.com


Top
 Profile  
 
 Post subject: Re: Can't find hibernate-configuration-3.0.dtd
PostPosted: Thu Jun 04, 2009 6:00 am 
Newbie

Joined: Wed Feb 18, 2009 4:26 am
Posts: 7
Anyway, a workaround is to download the hibernate-configuration-3.0.dtd & hibernate-mapping-3.0.dtd.
To put it in your classpath.
And to replace the :
Code:
http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd

with :
Code:
classpath://hibernate-mapping-3.0.dtd

in hibernate.cfg.xml and each .hbm.xml file...

_________________
--
www.sporevo.com


Top
 Profile  
 
 Post subject: Re: Can't find hibernate-configuration-3.0.dtd
PostPosted: Tue Mar 19, 2013 9:15 pm 
Newbie

Joined: Tue Mar 19, 2013 9:09 pm
Posts: 3
you can try mapping to dtd inside jar on hibernateXXX.jar with the following lines:

Code:
<!DOCTYPE hibernate-mapping PUBLIC
   "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
   "classpath://org/hibernate/hibernate-mapping-3.0.dtd">


it will depends of jar version, but for 3.0 version this should be the solution.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.