日期:2014-05-19  浏览次数:20693 次

hibernate4 在用annotation映射是老是出错,为什么呀
Exception in thread "main" org.hibernate.MappingException: Unable to load class [ cn.lcc.hibernaet.model.MyTeacher] declared in Hibernate configuration <mapping/> entry

Caused by: java.lang.ClassNotFoundException: cn.lcc.hibernaet.model.MyTeacher

刚刚学习hibernate 真心不懂,我直接贴代码吧
先上异常吧

Java code

七月 24, 2012 10:36:03 上午 org.hibernate.annotations.common.Version <clinit>
INFO: HCANN000001: Hibernate Commons Annotations {4.0.1.Final}
七月 24, 2012 10:36:03 上午 org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {4.1.5.Final}
七月 24, 2012 10:36:03 上午 org.hibernate.cfg.Environment <clinit>
INFO: HHH000206: hibernate.properties not found
七月 24, 2012 10:36:03 上午 org.hibernate.cfg.Environment buildBytecodeProvider
INFO: HHH000021: Bytecode provider name : javassist
七月 24, 2012 10:36:03 上午 org.hibernate.cfg.Configuration configure
INFO: HHH000043: Configuring from resource: /hibernate.cfg.xml
七月 24, 2012 10:36:03 上午 org.hibernate.cfg.Configuration getConfigurationInputStream
INFO: HHH000040: Configuration resource: /hibernate.cfg.xml
七月 24, 2012 10:36:03 上午 org.hibernate.cfg.Configuration addResource
INFO: HHH000221: Reading mappings from resource: cn/lcc/hibernate/model/User.hbm.xml
Exception in thread "main" org.hibernate.MappingException: Unable to load class [ cn.lcc.hibernaet.model.MyTeacher] declared in Hibernate configuration <mapping/> entry
    at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:2133)
    at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:2081)
    at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2061)
    at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2014)
    at org.hibernate.cfg.Configuration.configure(Configuration.java:1929)
    at org.hibernate.cfg.Configuration.configure(Configuration.java:1908)
    at cn.lcc.hibernate.test.HBTest.testMyTeacher(HBTest.java:54)
    at cn.lcc.hibernate.test.HBTest.main(HBTest.java:107)
Caused by: java.lang.ClassNotFoundException: cn.lcc.hibernaet.model.MyTeacher
    at java.net.URLClassLoader$1.run(Unknown Source)
    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.internal.util.ReflectHelper.classForName(ReflectHelper.java:192)
    at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:2130)
    ... 7 more




这是我的配置文件,hibernate.cfg.xml
XML code

<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
        "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
        "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">

<hibernate-configuration>
    <session-factory>

        <!-- D