/ / funcional hibernate.cfg.xml para o hibernate 4 - hibernate

hibernate.cfg.xml funcional para o hibernate 4 - hibernate

Alguém tem um exemplo de arquivo cfg funcionalpara hibernar 4? Toda a referência que eu posso encontrar on-line é para menos de v4 e isso não funciona. Eu tentei colar o conteúdo do meu arquivo aqui, mas este site remove a tag de configuração de hibernação.

então aqui está o que sai:

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD//EN"
"http://www.hibernate.org/dtd/">

<hibernate-configuration xmlns="http://www.hibernate.org/xsd/hibernate-configuration">

<session-factory>

<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<!-- Assume test is the database name -->
<property name="hibernate.connection.url">jdbc:mysql://localhost/foampile</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password"></property>
<!-- List of XML mapping files -->

<mapping resource="SiteRecord.hbm.xml"/>

</session-factory>

</hibernate-configuration>

quando eu mudar para

<hibernate-configuration xmlns="http://www.hibernate.org/xsd/hibernate-configuration"
xsi:schemaLocation="http://www.hibernate.org/xsd/hibernate-configuration hibernate-configuration-4.0.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

Eu recebo esta exceção:

Caused by: org.xml.sax.SAXParseException; lineNumber: 9; columnNumber: 63; Attribute "xmlns" must be declared for element type "hibernate-configuration".

MAS xmlns IS especificado (xmlns = "http://www.hibernate.org/xsd/hibernate-configuration")

É ESTE UM ERRO EM HIBERNA 4.1?

Respostas:

2 para resposta № 1

Eu tive o mesmo problema e conseguipara trabalhar apenas removendo todos os atributos da configuração do hibernate, apesar do que a documentação e as mensagens de erro dizem :) Então, no final, eu tenho isso para o meu DOCTYPE:

<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">

e então eu só tenho:

<hibernate-configuration>
....
</hibernate-configuration>

e isso funciona para mim.


1 para resposta № 2

... pelo que vale a pena, acabei tendo o IntelliJ criado o arquivo stub, apenas para começar a usá-lo (para o hibernate 4.1):

<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">