我有Hibernate.I一個項目試圖讀取配置文件hibernate.cfg和得到這個錯誤:Hibernate映射錯誤:MappingException:一個AnnotationConfiguration實例
Error creando una factoria de session.org.hibernate.MappingException: An AnnotationConfiguration instance is required to use <mapping class="com/david/Categoria"/>
jun 04, 2013 10:19:26 AM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: El Servlet.service() para el servlet [ControladorLibros] en el contexto con ruta [/App01HTML] lanzó la excepción [La ejecución del Servlet lanzó una excepción] con causa raíz
org.hibernate.MappingException: An AnnotationConfiguration instance is required to use <mapping class="com/david/Categoria"/>
at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:1524)
at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1479)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1458)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1432)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1352)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1338)
at com.david.HibernateHelper.buildSessionFactory(HibernateHelper.java:13)
我的配置文件是如此的簡單:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://localhost/arquitecturajava</property>
<property name="connection.username">root</property>
<property name="connection.password">root</property>
<property name="connection.pool_size">5</property>
<property name="dialect">org.hibernate.dialect.MySQL5Dialect</property>
<property name="show_sql">true</property>
<mapping class="com/david/Categoria"></mapping>
<mapping class="com/david/Libro"></mapping>
</session-factory>
</hibernate-configuration>
不接受映射類線。
創建類似下面的代碼去配置:
private static SessionFactory buildSessionFactory()
{
try
{
return new Configuration().configure().buildSessionFactory();
}
catch (Throwable ex)
{
System.err.println("Error creando una factoria de session." + ex);
throw new ExceptionInInitializerError(ex);
}
}
和我的項目庫:
任何想法?
您正在使用哪個版本的Hibernate?順便說一句,一個類的符合條件的名字是com.david.Categoria,而不是com/david/Categoria。 –
錯誤與com/david/Categoria或com.david.Categoria相同。 – Davidin073
我的Hibernate版本<4,但我不確定是3.5還是3.3或其他。 – Davidin073