0

I am trying to mapping a Mysql table with Hibernate, but I get the next error when I execute the application:

Error creando una factoria de session.org.hibernate.MappingException: invalid   configuration
oct 04, 2014 10:23:31 PM org.apache.catalina.core.StandardWrapperValve invoke
Grave: El Servlet.service() para el servlet [com.Utiles.Controlador.ControladorInsertar]        en el contexto con ruta [/Libreria] lanzó la excepción [La ejecución del Servlet lanzó una      excepción] con causa raíz
org.xml.sax.SAXParseException; lineNumber: 3; columnNumber: 25; El documento no es válido:    no se ha encontrado la gramática.

I have this Eclipse files configuration:enter image description here

This is my Hibernate config file:

<?xml version='1.0' encoding='utf-8'?>

 <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">
<session-factory>
<!-- Database connection settings -->
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://localhost/proyecto</property>
<property name="connection.username">root</property>
<property name="connection.password">root</property>

<!-- JDBC connection pool (use the built-in) -->
<property name="connection.pool_size">20</property>

<!-- SQL dialect -->
<property name="dialect">org.hibernate.dialect.MySQL5Dialect</property>

<!-- Echo all executed SQL to stdout -->
<property name="show_sql">true</property>

<!-- Drop and re-create the database schema on startup -->
<mapping resource="com.Utiles.Libro.xml"/>
</session-factory>
</hibernate-configuration>

And this my Libro.xml file:

<?xml version="1.0"?>
<hibernate-mapping package="com.Utiles">
<class name="Libro" table="libros">
    <id name="isbn" type="String" />
    <property name="titulo" type="String" column="titulo" />
    <property name="categoria" type="String" column="categoria" />
</class>
</hibernate-mapping>

Coud you help me?

Thanks in advance

1 Answer 1

1

If I remember correctly you need to assign type of property either with full class name java.lang.String or with predefined type string. So update your Libro.xml to;

    <?xml version="1.0"?>
    <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
             "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
    <hibernate-mapping package="com.Utiles">
    <class name="Libro" table="libros">
        <id name="isbn" type="java.lang.String" />
        <property name="titulo" type="java.lang.String" column="titulo" />
        <property name="categoria" type="java.lang.String" column="categoria" />
    </class>
    </hibernate-mapping>

Also try to add DOCTYPE in your Libro.xml

Hope it helps.

4
  • Try again, I updated my answer. But also, you should provide more information? Libro source, ControladorInsertar source... Oct 5, 2014 at 15:56
  • It works!!!Adding DOCTYPE header, the configuration could be loaded and the database was modified correctly. Thanks a lot Oct 5, 2014 at 16:23
  • Another question...what must I do if I want to replace this xml for Hibernate annotations? In Hibernate 3 it was with @Entity and @@Table(name="Libros") annotations in Libro class, but I think that they are deprecated. Oct 5, 2014 at 17:08
  • They aren't deprecated, you can use it. Also, how to setup project to use annotation is one of FAQ questions, so google it. Here is official hibernate tutorial docs.jboss.org/hibernate/annotations/3.5/reference/en/html/… Oct 6, 2014 at 9:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.