休眠4.0.0。 CR4:org.hibernate.internal.util.config.ConfigurationException 与 hibernate.cfg.xml
嗨,我有以下 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 hsqldb
我收到此错误。
org.hibernate.internal.util.config.ConfigurationException:无法在 RESOURCE hibernate.cfg.xml 中的第 4 行和第 26 列处执行解组。消息:cvc-elt.1:找不到元素“hibernate-configuration”的声明。 在 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()
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()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我遇到了同样的问题,在邮件列表中找到的稍微不满意的答案是:
在这里找到:http://www.mail-archive。 com/[电子邮件受保护]/msg06948.html
I had the very same problem and the slightly unsatisfactory answer found in the mailing list is:
Found here: http://www.mail-archive.com/[email protected]/msg06948.html