【问题标题】:hibernate 4.0.0. CR4: org.hibernate.internal.util.config.ConfigurationException with hibernate.cfg.xml休眠 4.0.0。 CR4:org.hibernate.internal.util.config.ConfigurationException with hibernate.cfg.xml
【发布时间】:2011-11-30 09:08:05
【问题描述】:

嗨,我有以下 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>

在我的测试中我有。

@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());
}

我正在使用休眠 4.0.0.CR4 数据库数据库

我收到此错误。

org.hibernate.internal.util.config.ConfigurationException:无法在资源 hibernate.cfg.xml 中的第 4 行和第 26 列执行解组。消息:cvc-elt.1:找不到元素“休眠配置”的声明。 在 org.hibernate.service.internal.JaxbProcessor.unmarshal(JaxbProcessor.java:120) 在 org.hibernate.service.internal.JaxbProcessor.unmarshal(JaxbProcessor.java:69) 在 org.hibernate.service.ServiceRegistryBuilder.configure(ServiceRegistryBuilder.java:162) 在 org.hibernate.service.ServiceRegistryBuilder.configure(ServiceRegistryBuilder.java:147) 引起:javax.xml.bind.UnmarshalException - 有关联的例外: [org.xml.sax.SAXParseException: cvc-elt.1: 找不到元素“hibernate-configuration”的声明。]

代码在 hibernate 3.6 GA 中工作,但无法在 hibernate 4 上运行(忽略编译错误)。

怎么了?


抱歉还是不行。我什至尝试过使用 MetaDataSources 构建器。

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

【问题讨论】:

  • 有人有解决方案吗?我遇到了同样的问题。 ServiceRegistry 在 4.0 中似乎比较新,所以没有太多关于如何使用它的信息。

标签: hibernate parsing marshalling hibernate.cfg.xml


【解决方案1】:

我遇到了同样的问题,在邮件列表中找到的稍微不满意的答案是:

这项工作仍在进行中。

在这里找到:http://www.mail-archive.com/hibernate-dev@lists.jboss.org/msg06948.html

【讨论】:

  • 啊谢谢。好吧,如果您与弹簧相结合,那么它就可以工作... ;)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-02-21
  • 2016-06-14
  • 2015-04-06
  • 1970-01-01
  • 1970-01-01
  • 2016-06-29
相关资源
最近更新 更多