Reputation: 1179
I want to use Configuration() methot. But I get this error:
Initial SessionFactory creation failed.org.hibernate.MappingException: An AnnotationConfiguration instance is required to use <mapping class="com.example.domain.Lesson"/>
If I use AnnotationConfiguratin() method, Hibernate can read my classes. I don't understand this:
Why when I use Configuration method, Hibernate can't see <mapping class="com.example.Lesson"/>
definition?
My hibernate.cfg.xml
file :
<?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>
My Lesson class :
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..
}
I had bhm.xml files from reverse engineering.
So, I don't want to use Annotation.
Any idea?
Upvotes: 3
Views: 1756
Reputation: 34900
Just remove <mapping class="com.example.Lesson"/>
from hibernate.cfg.xml
. It is not necessary because Lesson.hbm.xml
is present.
Upvotes: 1