hibernate中映射异常的一种

log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.
%%%% Error Creating SessionFactory %%%%
org.hibernate.InvalidMappingException: Could not parse mapping document from resource cn/itcast/hibernate/domain/Employee.hbm.xml
at org.hibernate.cfg.Configuration.addResource(Configuration.java:588)
at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:1606)
at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1574)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1553)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1527)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1447)
at cn.itcast.hibernate.HibernateSessionFactory.<clinit>(HibernateSessionFactory.java:30)
at cn.itcast.hibernate.Many2One.add(Many2One.java:90)
at cn.itcast.hibernate.Many2One.main(Many2One.java:25)
Caused by: org.hibernate.MappingException: class Skiller not found while looking for property: skill
at org.hibernate.util.ReflectHelper.reflectedPropertyClass(ReflectHelper.java:209)
at org.hibernate.mapping.SimpleValue.setTypeUsingReflection(SimpleValue.java:279)
at org.hibernate.cfg.HbmBinder.createProperty(HbmBinder.java:2171)
at org.hibernate.cfg.HbmBinder.createClassProperties(HbmBinder.java:2148)
at org.hibernate.cfg.HbmBinder.createClassProperties(HbmBinder.java:2038)
at org.hibernate.cfg.HbmBinder.bindSubclass(HbmBinder.java:820)
at org.hibernate.cfg.HbmBinder.handleSubclass(HbmBinder.java:2217)
at org.hibernate.cfg.HbmBinder.createClassProperties(HbmBinder.java:2108)
at org.hibernate.cfg.HbmBinder.createClassProperties(HbmBinder.java:2038)
at org.hibernate.cfg.HbmBinder.bindRootPersistentClassCommonValues(HbmBinder.java:359)
at org.hibernate.cfg.HbmBinder.bindRootClass(HbmBinder.java:273)
at org.hibernate.cfg.HbmBinder.bindRoot(HbmBinder.java:144)
at org.hibernate.cfg.Configuration.add(Configuration.java:688)
at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:523)
at org.hibernate.cfg.Configuration.addResource(Configuration.java:585)
... 8 more
Caused by: java.lang.ClassNotFoundException: Skiller
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:169)
at org.hibernate.util.ReflectHelper.classForName(ReflectHelper.java:169)
at org.hibernate.util.ReflectHelper.reflectedPropertyClass(ReflectHelper.java:205)
... 22 more
%%%% Error Creating SessionFactory %%%%
org.hibernate.InvalidMappingException: Could not parse mapping document from resource cn/itcast/hibernate/domain/Employee.hbm.xml
at org.hibernate.cfg.Configuration.addResource(Configuration.java:588)
at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:1606)
at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1574)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1553)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1527)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1447)
at cn.itcast.hibernate.HibernateSessionFactory.rebuildSessionFactory(HibernateSessionFactory.java:69)
at cn.itcast.hibernate.HibernateSessionFactory.getSession(HibernateSessionFactory.java:53)
at cn.itcast.hibernate.Many2One.add(Many2One.java:90)
at cn.itcast.hibernate.Many2One.main(Many2One.java:25)
Caused by: org.hibernate.MappingException: class Skiller not found while looking for property: skill
at org.hibernate.util.ReflectHelper.reflectedPropertyClass(ReflectHelper.java:209)
at org.hibernate.mapping.SimpleValue.setTypeUsingReflection(SimpleValue.java:279)
at org.hibernate.cfg.HbmBinder.createProperty(HbmBinder.java:2171)
at org.hibernate.cfg.HbmBinder.createClassProperties(HbmBinder.java:2148)
at org.hibernate.cfg.HbmBinder.createClassProperties(HbmBinder.java:2038)
at org.hibernate.cfg.HbmBinder.bindSubclass(HbmBinder.java:820)
at org.hibernate.cfg.HbmBinder.handleSubclass(HbmBinder.java:2217)
at org.hibernate.cfg.HbmBinder.createClassProperties(HbmBinder.java:2108)
at org.hibernate.cfg.HbmBinder.createClassProperties(HbmBinder.java:2038)
at org.hibernate.cfg.HbmBinder.bindRootPersistentClassCommonValues(HbmBinder.java:359)
at org.hibernate.cfg.HbmBinder.bindRootClass(HbmBinder.java:273)
at org.hibernate.cfg.HbmBinder.bindRoot(HbmBinder.java:144)
at org.hibernate.cfg.Configuration.add(Configuration.java:688)
at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:523)
at org.hibernate.cfg.Configuration.addResource(Configuration.java:585)
... 9 more
Caused by: java.lang.ClassNotFoundException: Skiller
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:169)
at org.hibernate.util.ReflectHelper.classForName(ReflectHelper.java:169)
at org.hibernate.util.ReflectHelper.reflectedPropertyClass(ReflectHelper.java:205)
... 23 more
Exception in thread "main" java.lang.NullPointerException
at cn.itcast.hibernate.Many2One.add(Many2One.java:91)

at cn.itcast.hibernate.Many2One.main(Many2One.java:25)

=======================================================================================================

hibernate中java.lang.ClassNotFoundException,找不到Skiller类

在映射文件中,指定某个类时,不仅要写上类名,而且要加上包名。即:包名+类名

        <subclass name="cn.itcast.hibernate.domain.Skiller" discriminator-value="1">
           <property name="skill"></property>
        </subclass>
        <subclass name="cn.itcast.hibernate.domain.Sales" discriminator-value="2">
           <property name="sell"></property>
        </subclass>

积少成多,愿有一天可以轻松的改正错误。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值