hibernate 4.0.0. CR4: org.hibernate.internal.util.config.ConfigurationException with hibernate.cfg.xml

白昼怎懂夜的黑 提交于 2019-12-11 10:49:35

问题


Hi i have the following hibernate.cfg.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration SYSTEM 
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory name="myFactory">
    <property   name="hibernate.connection.driver_class">org.hsqldb.jdbcDriver</property>
    <property   name="hibernate.connection.url">jdbc:hsqldb:mem:EnumTypeTest</property>
    <property name="hibernate.connection.username">sa</property>
    <property   name="hibernate.dialect">org.hibernate.dialect.HSQLDialect</property>
    <property name="hibernate.hbm2ddl.auto">create-drop</property>
    <property name="hibernate.connection.pool_size">10</property>
    <mapping resource="com/test/domain/DomainWithEnumInt.hbm.xml" />
</session-factory>
 </hibernate-configuration>

In my test i have.

@Test
public void testWriteEnumWithInt() {
     this.sessionFactory = new Configuration()
            .buildSessionFactory(new       ServiceRegistryBuilder().configure().buildServiceRegistry());
    final DomainWithEnumInt dwei = new DomainWithEnumInt(EnumIntType.Two);
    this.sessionFactory.withOptions().save(dwei);
    Assert.assertNotNull(dwei.getId());
}

I am using hibernate 4.0.0.CR4 hsqldb

I get this error.

org.hibernate.internal.util.config.ConfigurationException: Unable to perform unmarshalling at line number 4 and column 26 in RESOURCE hibernate.cfg.xml. Message: cvc-elt.1: Cannot find the declaration of element 'hibernate-configuration'. at org.hibernate.service.internal.JaxbProcessor.unmarshal(JaxbProcessor.java:120) at org.hibernate.service.internal.JaxbProcessor.unmarshal(JaxbProcessor.java:69) at org.hibernate.service.ServiceRegistryBuilder.configure(ServiceRegistryBuilder.java:162) at org.hibernate.service.ServiceRegistryBuilder.configure(ServiceRegistryBuilder.java:147) Caused by: javax.xml.bind.UnmarshalException - with linked exception: [org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration of element 'hibernate-configuration'.]

the code works in hibernate 3.6 GA but fails to run on hibernate 4 (disregarding the compile error).

What is wrong?


Sorry still doesn't work. I even tried using MetaDataSources builder.

new MetadataSources(new ServiceRegistryBuilder()
                .configure()
                .buildServiceRegistry())
                .buildMetadata().
                buildSessionFactory()

回答1:


I had the very same problem and the slightly unsatisfactory answer found in the mailing list is:

This is still work in progress.

Found here: http://www.mail-archive.com/hibernate-dev@lists.jboss.org/msg06948.html



来源:https://stackoverflow.com/questions/7643074/hibernate-4-0-0-cr4-org-hibernate-internal-util-config-configurationexception

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!