组件属性问题

来源:3-5 [Hibernate单表操作] 组件属性

淡淡_幸福

2016-01-03 21:59

org.hibernate.InvalidMappingException: Could not parse mapping document from resource Students.hbm.xml

at org.hibernate.cfg.Configuration$MetadataSourceQueue.processHbmXml(Configuration.java:3819)

at org.hibernate.cfg.Configuration$MetadataSourceQueue.processHbmXmlQueue(Configuration.java:3808)

at org.hibernate.cfg.Configuration$MetadataSourceQueue.processMetadata(Configuration.java:3796)

at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1412)

at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1846)

at StudentsTest.init(StudentsTest.java:34)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

at java.lang.reflect.Method.invoke(Unknown Source)

at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)

at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)

at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)

at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:27)

at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:30)

at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)

at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)

at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)

at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)

at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)

at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)

at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)

at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)

at org.junit.runners.ParentRunner.run(ParentRunner.java:300)

at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)

at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)

at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)

at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)

at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)

at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)

Caused by: org.hibernate.MappingException: class Address not found while looking for property: postcode

at org.hibernate.internal.util.ReflectHelper.reflectedPropertyClass(ReflectHelper.java:233)

at org.hibernate.mapping.SimpleValue.setTypeUsingReflection(SimpleValue.java:375)

at org.hibernate.cfg.HbmBinder.createProperty(HbmBinder.java:2370)

at org.hibernate.cfg.HbmBinder.bindComponent(HbmBinder.java:2057)

at org.hibernate.cfg.HbmBinder.createClassProperties(HbmBinder.java:2274)

at org.hibernate.cfg.HbmBinder.createClassProperties(HbmBinder.java:2224)

at org.hibernate.cfg.HbmBinder.bindRootPersistentClassCommonValues(HbmBinder.java:412)

at org.hibernate.cfg.HbmBinder.bindRootClass(HbmBinder.java:327)

at org.hibernate.cfg.HbmBinder.bindRoot(HbmBinder.java:178)

at org.hibernate.cfg.Configuration$MetadataSourceQueue.processHbmXml(Configuration.java:3816)

... 29 more

Caused by: java.lang.ClassNotFoundException: Address

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:193)

at org.hibernate.internal.util.ReflectHelper.reflectedPropertyClass(ReflectHelper.java:229)

... 38 more


java.lang.NullPointerException

at StudentsTest.destory(StudentsTest.java:42)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

at java.lang.reflect.Method.invoke(Unknown Source)

at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)

at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)

at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)

at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:36)

at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)

at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)

at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)

at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)

at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)

at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)

at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)

at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)

at org.junit.runners.ParentRunner.run(ParentRunner.java:300)

at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)

at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)

at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)

at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)

at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)

at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)

我的配置中感觉也没错啊,怎么就找不到呢,而且还找不到Address这个类,是怎么回事?

写回答 关注

6回答

  • 小蜗牛有大理想
    2018-01-11 00:29:36

    改了没有用

  • 岳阳白少
    2016-03-18 13:44:31

    改了没用啊

  • 淡淡_幸福
    2016-02-11 21:04:29

    恩,还是出错啊

  • Refactor易先生
    2016-02-05 19:27:48

    这样改了还是没有用、、、、

  • 淡淡_幸福
    2016-01-08 16:32:04

    我的Student.hbm.xml配置文件中就是这样写的<class name="com.hp.hibernate.Students" table="STUDENTS">,对吗?

  • 堂堂堂堂糖糖糖童鞋
    2016-01-04 12:03:14
    Caused by: java.lang.ClassNotFoundException: Address

    在Student.hbm.xml文件中 class的name属性要写全路径,如:

    <class name="com.imooc.hibernate5.model.Student" table="STUDENT">

    或者这样:

    <hibernate-mapping package="com.imooc.hibernate5.model">
        <class name="Student" table="STUDENT">

    在hibernate-mapping中指定包名,在class 的name属性中只指定类名!

Hibernate初探之单表映射

Java持久化框架Hibernate入门教程,掌握Hibernate基本概念

74810 学习 · 793 问题

查看课程

相似问题