2012-08-30 15 views
6

¿Alguien tiene un ejemplo de archivo cfg funcional para hibernate 4? Toda la referencia que puedo encontrar en línea es por menos de v4 y eso no funciona. Traté de pegar el contenido de mi archivo aquí, pero este sitio elimina la etiqueta de configuración de hibernación.hibernate.cfg.xml funcional para hibernar 4

así que aquí es lo que sale:

<?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> 

vez que me cambio a

<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"> 

me sale esta excepción:

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

PERO xmlns se especifica (xmlns = "http : //www.hibernate.org/xsd/hibernate-configuration ")

¿ES ESTE UN ERROR EN HIBERNATE 4.1 ???

+0

Parece que el problema es con! DOCTYPE pero no sé a qué configurarlo. si lo configuro para el que tiene referencia a v3 DTD, falla al analizar de nuevo y si no incluyo el tipo de documento, se queja de que hibernate-configuration no tiene el atributo xmlns ... SOY EXTREMADAMENTE FRUSTRADO CON ESTO, DESPERDICIADO LAST 2 HRS – amphibient

+0

el documento en línea de Hibernate 4 muestra un ejemplo sin DOCTYPE. – amphibient

+0

http://docs.jboss.org/hibernate/orm/4.1/devguide/en-US/html/ch01.html#d5e83 – amphibient

Respuesta

1

... para lo que vale, que llegó a tener IntelliJ creó el archivo de código auxiliar, sólo para obtener un comienzo en el mismo (para hibernar 4.1):

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

tuve el mismo problema y que estaba capaz de conseguir que funcione con sólo la eliminación de todos los atributos de hibernación configuración, a pesar de lo que los mensajes de error de documentación y dicen :) Así que al final, tengo esto para mi DOCTYPE:

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

y luego acabo tener:

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

y eso funciona para mí.