使用Hibernate加载配置时出现问题

时间:2014-10-04 20:31:02

标签: java eclipse hibernate

我正在尝试使用Hibernate映射Mysql表,但是当我执行应用程序时出现下一个错误:

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.

我有这个Eclipse文件配置:enter image description here

这是我的Hibernate配置文件:

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

这是我的Libro.xml文件:

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

提前致谢

1 个答案:

答案 0 :(得分:1)

如果我没记错的话,您需要使用完整的班级名称java.lang.String或预定义的类型string来指定属性类型。所以将你的Libro.xml更新为;

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

还尝试在Libro.xml中添加DOCTYPE

希望它有所帮助。