开发者社区> 问答> 正文

hibernate 删除的时候报错了。求解????报错

Hibernate: select users0_.id as id0_, users0_.username as username0_, users0_.password as password0_ from Users users0_
org.hibernate.MappingException: Unknown entity: java.lang.Integer
at org.hibernate.impl.SessionFactoryImpl.getEntityPersister(SessionFactoryImpl.java:628)
at org.hibernate.impl.SessionImpl.getEntityPersister(SessionImpl.java:1366)
at org.hibernate.event.def.DefaultDeleteEventListener.onDelete(DefaultDeleteEventListener.java:100)
at org.hibernate.event.def.DefaultDeleteEventListener.onDelete(DefaultDeleteEventListener.java:74)
at org.hibernate.impl.SessionImpl.fireDelete(SessionImpl.java:794)
at org.hibernate.impl.SessionImpl.delete(SessionImpl.java:772)
at org.accp.ay213.dao.Impl.UserDaoImpl.deleteUser(UserDaoImpl.java:88)
at org.accp.ay213.services.Impl.UserservicesImpl.deleteUser(UserservicesImpl.java:33)
at org.accp.ay213.servlet.deleteUserInfo.doPost(deleteUserInfo.java:43)
at org.accp.ay213.servlet.deleteUserInfo.doGet(deleteUserInfo.java:35)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:723)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:879)
at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:617)
at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1760)
at java.lang.Thread.run(Thread.java:619)
Hibernate: select users0_.id as id0_, users0_.username as username0_, users0_.password as password0_ from Users users0_
org.hibernate.MappingException: Unknown entity: java.lang.Integer
at org.hibernate.impl.SessionFactoryImpl.getEntityPersister(SessionFactoryImpl.java:628)
at org.hibernate.impl.SessionImpl.getEntityPersister(SessionImpl.java:1366)
at org.hibernate.event.def.DefaultDeleteEventListener.onDelete(DefaultDeleteEventListener.java:100)
at org.hibernate.event.def.DefaultDeleteEventListener.onDelete(DefaultDeleteEventListener.java:74)
at org.hibernate.impl.SessionImpl.fireDelete(SessionImpl.java:794)
at org.hibernate.impl.SessionImpl.delete(SessionImpl.java:772)
at org.accp.ay213.dao.Impl.UserDaoImpl.deleteUser(UserDaoImpl.java:88)
at org.accp.ay213.services.Impl.UserservicesImpl.deleteUser(UserservicesImpl.java:33)
at org.accp.ay213.servlet.deleteUserInfo.doPost(deleteUserInfo.java:43)
at org.accp.ay213.servlet.deleteUserInfo.doGet(deleteUserInfo.java:35)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:723)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:879)
at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:617)
at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1760)
at java.lang.Thread.run(Thread.java:619)
Hibernate: select users0_.id as id0_, users0_.username as username0_, users0_.password as password0_ from Users users0_
Hibernate: select users0_.id as id0_0_, users0_.username as username0_0_, users0_.password as password0_0_ from Users users0_ where users0_.id=?


展开
收起
爱吃鱼的程序员 2020-06-22 14:20:38 450 0
1 条回答
写回答
取消 提交回答
  • https://developer.aliyun.com/profile/5yerqm5bn5yqg?spm=a2c6h.12873639.0.0.6eae304abcjaIB

    目测是ORM的映射类型有误~~比如你DAO层的删除方法传入的参数类型有误???没看到你的DAO代码,所以难说,不过从报错信息看,十有八九是delete方法的参数有误!!

    查之~~改之~~

    回复 @我的中国梦:那么你的DAO方法里头,是否真的是接受int参数进行delete呢??~~~~另外如果你是采用hibernate自动生成DAO,那么更应该确认一下DAO的情况~~比如“getHibernateTemplate().delete()参数是一个pojo的实例”我穿的参数都是int类型的啊!我就在servlet里面有了一次string类型的转换,转换成了Integer。show_sql,看看打印出的SQL语句呗.还是JDBC好.Hibernate:selectusers0_.idasid0_,users0_.usernameasusername0_,users0_.passwordaspassword0_fromUsersusers0_应该是没找到要 删除的实体我用的是oracle,在oracle中id为number类型,我做删除是通过id来删除的,我就只在servlet里面做了一下转换integer。

    lz你是不是这样写的delete方法

    session.delete(id)

    Sessionsession=null;Usersuser=(Users)session.get(Users.class,id);session.delete(user);

    贴下你的代码啊

    atorg.accp.ay213.dao.Impl.UserDaoImpl.deleteUser(UserDaoImpl.java:88)atorg.accp.ay213.services.Impl.UserservicesImpl.deleteUser(UserservicesImpl.java:33)atorg.accp.ay213.servlet.deleteUserInfo.doPost(deleteUserInfo.java:43)atorg.accp.ay213.servlet.deleteUserInfo.doGet(deleteUserInfo.java:35)

    这是你报错的代码位置。北大青鸟的项目???



    用hibernate自己的删除应该传入的是实体类对象,不是主键ID,至少new一个对象set一下主键ID再调用delete方法。如果直接使用ID删除,就自己写删除的sql语句。对哦!谢谢。但是我改了Sessionsession=null;
    try{
    Usersuser=(Users)session.get(Users.class,id);

    session.delete(user);

    这也报错啊!

    2020-06-23 11:57:58
    赞同 展开评论 打赏
问答分类:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载