生成表报错,代码都检查过了,没有什么问题啊,我用的是User不是Users

来源:1-6 生成表结构

晟晟online

2016-12-14 20:55

org.hibernate.MappingException: entity class not found: User

at org.hibernate.mapping.PersistentClass.getMappedClass(PersistentClass.java:129)

at org.hibernate.tuple.PropertyFactory.getGetter(PropertyFactory.java:390)

at org.hibernate.tuple.PropertyFactory.buildIdentifierProperty(PropertyFactory.java:75)

at org.hibernate.tuple.entity.EntityMetamodel.<init>(EntityMetamodel.java:145)

at org.hibernate.persister.entity.AbstractEntityPersister.<init>(AbstractEntityPersister.java:507)

at org.hibernate.persister.entity.SingleTableEntityPersister.<init>(SingleTableEntityPersister.java:146)

at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)

at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)

at java.lang.reflect.Constructor.newInstance(Constructor.java:513)

at org.hibernate.persister.internal.PersisterFactoryImpl.create(PersisterFactoryImpl.java:163)

at org.hibernate.persister.internal.PersisterFactoryImpl.createEntityPersister(PersisterFactoryImpl.java:135)

at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:385)

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

at entity.TestGoods.testSchemaExport(TestGoods.java:23)

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

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

at java.lang.reflect.Method.invoke(Method.java:597)

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.InvokeMethod.evaluate(InvokeMethod.java:20)

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

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

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

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

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

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

Caused by: java.lang.ClassNotFoundException: User

at java.net.URLClassLoader$1.run(URLClassLoader.java:202)

at java.security.AccessController.doPrivileged(Native Method)

at java.net.URLClassLoader.findClass(URLClassLoader.java:190)

at java.lang.ClassLoader.loadClass(ClassLoader.java:306)

at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)

at java.lang.ClassLoader.loadClass(ClassLoader.java:247)

at java.lang.Class.forName0(Native Method)

at java.lang.Class.forName(Class.java:171)

at org.hibernate.internal.util.ReflectHelper.classForName(ReflectHelper.java:192)

at org.hibernate.mapping.PersistentClass.getMappedClass(PersistentClass.java:126)

... 37 more

http://img.mukewang.com/5851412b0001688116000868.jpg

写回答 关注

4回答

  • 慕粉4271541
    2016-12-15 16:22:21
    已采纳

    我说的是映射文件User.hbm.xml里的,你上面是配置文件hibernate.cfg.xml,你看看映射文件里是不是<class name="po.User" table="USERS">

    慕粉4271... 回复晟晟onli...

    解决了就好,我也是尽我知道的回答你

    2016-12-19 17:02:38

    共 4 条回复 >

  • qq_青云路_03753951
    2017-03-09 21:56:42

    解决了吗?我也遇到类似问题

  • 晟晟online
    2016-12-15 10:54:48

    我写的User在po包下,上边图片可以看到。。

  • 慕粉4271541
    2016-12-14 22:32:30

    entity class not found User 的错误在于User在entity包下,那么映射文件中应为<class name="entity.User" table="USERS">

    晟晟onli...

    我写的User在po包下,上边图片可以看到。。

    2016-12-15 10:55:13

    共 1 条回复 >

使用Struts2+Hibernate开发学生信息管理功能

Strust2+Hibernate整合开发案例,Java Web开发技能更上一层楼

80701 学习 · 754 问题

查看课程

相似问题