我想使用 Configuration() 方法。但我得到这个错误:
Initial SessionFactory creation failed.org.hibernate.MappingException: An AnnotationConfiguration instance is required to use <mapping class="com.example.domain.Lesson"/>
如果我使用 AnnotationConfiguratin() 方法,Hibernate 可以读取我的类。我不明白这一点:
为什么当我使用 Configuration 方法时,Hibernate 看不到<mapping class="com.example.Lesson"/>
定义?
我的hibernate.cfg.xml
文件:
<?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="hibernate.connection.driver_class">org.postgresql.Driver</property>
<property name="hibernate.connection.password">****</property>
<property name="hibernate.connection.url">jdbc:postgresql://localhost:5432/DB</property>
<property name="hibernate.connection.username">postgres</property>
<property name="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</property>
<mapping resource="com.example/Lesson.hbm.xml" />
<mapping class="com.example.Lesson"/>
</session-factory>
</hibernate-configuration>
我的课:
public class Lesson implements java.io.Serializable {
private int id;
private String lesson;
private Set lessons = new HashSet(0);
public Lesson() {
}
public Lesson(int id, String lesson, Set lessons) {
this.id = id;
this.id = id;
this.lessons = lessons;
}
continue..
}
我有来自所以的 bhm.xml 文件reverse engineering.
,我不想使用注释。
任何的想法?