Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hibernate issue with using http://www.hibernate.org/dtd [duplicate]

I'm currently using http://hibernate.sourceforge.net as my namespace in my hibernate configuration files which gives me these warnings:

Recognized obsolete hibernate namespace http://hibernate.sourceforge.net/. Use namespace http://www.hibernate.org/dtd/ instead. Refer to Hibernate 3.6 Migration Guide!

So I tried switching hibernate.cfg.xml and all the other *.hbm.xml files to using http://www.hibernate.org/dtd. However then when I try to generate the code using hibernate tools in eclipse I get the following error message (code generation works fine with the other namespace):

org.hibernate.HibernateException: Could not parse configuration: C:\dev\workspace\DataLoad\hibernate.cfg.xml Could not parse configuration: C:\dev\workspace\DataLoad\hibernate.cfg.xml
org.dom4j.DocumentException: www.hibernate.org Nested exception: www.hibernate.org www.hibernate.org Nested exception: www.hibernate.org org.dom4j.DocumentException: www.hibernate.org Nested exception: www.hibernate.org www.hibernate.org Nested exception: www.hibernate.org

Here's my hibernate.cfg.xml:

<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
        "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
        "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">

<hibernate-configuration>
    <session-factory>
        <!-- Database connection settings -->
        <property name="connection.driver_class">
            com.mysql.jdbc.Driver
        </property>
        <property name="connection.url">
            jdbc:mysql://localhost:3306/findata?tcpKeepAlive=true
        </property>
        <property name="connection.username">root</property>
        <property name="connection.password">xxxxxxxx</property>

        <property name="connection.pool_size">2</property>
        <property name="show_sql">true</property>
        <property name="dialect">
            org.hibernate.dialect.MySQLDialect
        </property>
        <property name="current_session_context_class">thread</property>
        <property name="cache.provider_class">
            org.hibernate.cache.NoCacheProvider
        </property>

        <mapping resource="conf/Alert.hbm.xml" />
        <mapping resource="conf/Entity.hbm.xml" />
        <mapping resource="conf/FactData.hbm.xml" />
        <mapping resource="conf/TimeEvent.hbm.xml" />
        <mapping resource="conf/User.hbm.xml" />
        <mapping resource="conf/AlertTarget.hbm.xml" />
        <mapping resource="conf/LogAlert.hbm.xml" />
        <mapping resource="conf/RepeatType.hbm.xml" />
        <mapping resource="conf/Schedule.hbm.xml" />
        <mapping resource="conf/Task.hbm.xml" />
        <mapping resource="conf/JobQueue.hbm.xml" />
        <mapping resource="conf/LogTask.hbm.xml" />
        <mapping resource="conf/Exclude.hbm.xml" />
        <mapping resource="conf/LogNotification.hbm.xml" />
        <mapping resource="conf/Job.hbm.xml" />
        <mapping resource="conf/Metric.hbm.xml" />
        <mapping resource="conf/EntityGroup.hbm.xml" />
        <mapping resource="conf/ExtractSingle.hbm.xml" />
    </session-factory>
</hibernate-configuration>
like image 558
opike Avatar asked Sep 11 '25 05:09

opike


1 Answers

We had also some problems parsing hibernate cfg files in last time. The root of the cause was that the hibernate site was unreachable. After some googling and debugging org.hibernate.util.DTDEntityResolver class, I realized that there is also another way, how to specify the DTD URL:

<!DOCTYPE hibernate-configuration SYSTEM
    "classpath://org/hibernate/hibernate-configuration-3.0.dtd">

This means that hibernate will load the DTD from classpath - it is usually included in hibernate jar in org/hibernate directory.

However, we use hibernate 3.5.6 - I don't hnow if this approach still works in the newer version - give it a try. The benefit of this is that you are completely independent on internet connection, proxies and so on.

like image 56
Foyta Avatar answered Sep 13 '25 18:09

Foyta