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

我的中国梦 发布于 2013/11/21 09:12
阅读 549
收藏 0
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=?

加载中
0
xyxo
xyxo

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

查之~~改之~~

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

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

session.delete(id)

我的中国梦
我的中国梦
Session session =null; Users user = (Users)session.get(Users.class, id); session.delete(user);
0
backtract
backtract

贴下你的代码啊

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)

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



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

session.delete(user);

这也报错啊!

返回顶部
顶部