为了账号安全,请及时绑定邮箱和手机立即绑定

组件属性问题

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 回答

改了没有用

0 回复 有任何疑惑可以回复我~

改了没用啊

0 回复 有任何疑惑可以回复我~

恩,还是出错啊

0 回复 有任何疑惑可以回复我~

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

0 回复 有任何疑惑可以回复我~

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

0 回复 有任何疑惑可以回复我~
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属性中只指定类名!

3 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消

组件属性问题

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信