嗨,我有以下的hibernate.cfg.xmlhibernate 4.0.0。 CR4:org.hibernate.internal.util.config.ConfigurationException与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'的声明。 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。配置(ServiceRegistryBuilder.java:162) at 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中似乎相当新颖,所以没有太多关于如何使用它的信息。 – DrColossos