【发布时间】: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