Hibernate菜鸟求助
我用的 Hibernate3.6.10版本 mysql版本5.5
文件:
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import com.bjsxt.hibernate.model.Student;
import com.bjsxt.hibernate.model.Teacher;
public class TeacherTest {
public static void main (String[] args){
Teacher t=new Teacher();
t.setId(1);
t.setName("t1");
t.setTitle("中级");
Configuration cfg= new Configuration();
SessionFactory sf= cfg.configure().buildSessionFactory();
Session session =sf.openSession();
session.beginTransaction();
session.save(t);
session.getTransaction().commit();
session.close();
sf.close();
}
}
出现问题提示:
Exception in thread "main"
org.hibernate.MappingException: Unable to load class [ com.bjsxt.hibernate.Teacher] declared in Hibernate configuration <mapping/> entry
at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:2369)
at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:2310)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2290)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2243)
at org.hibernate.cfg.Configuration.configure(Configuration.java:2158)
at org.hibernate.cfg.Configuration.configure(Configuration.java:2137)
at TeacherTest.main(TeacherTest.java:17)
Caused by:
java.lang.ClassNotFoundException: com.bjsxt.hibernate.Teacher
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at org.hibernate.util.ReflectHelper.classForName(ReflectHelper.java:192)
at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:2366)
... 6 more
我的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>
<!-- Database connection settings -->
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name