所以,解决方案为:1、确定你的数据库中存在符合要求的记录2、把load()换成get()
在按主键查询而没有找到对应的记录时,程序将出现ObjectNotFoundException——这是load()方法的特点之一。把load()换成get()。get()的特点是在没找到对应记录时返回null,而不会抛异常。
您还没有登录,请您登录后再发表评论
Hibernate Session中的 flush方法的作用 ...load方式检索不到的话会抛出org.hibernate.ObjectNotFoundException异常 get方法检索不到的话会返回null 2.从检索执行机制上对比: get方法和find方法都是直接从数据库中检索
javax.ejb.ObjectNotFoundException.class javax.ejb.RemoveException.class javax.ejb.SessionBean.class javax.ejb.SessionContext.class javax.ejb.SessionSynchronization.class javax.ejb.TimedObject.class ...
//该方法会延迟加载/获取数据(只有使用该对象中的字段时才会向数据库发出查询语句),该方法会在内部和二级缓存中查找数据,当数据库中没有要查询的数据时报ObjectNotFoundException异常 (7).createQuery(String HQL)...
javax.ejb.ObjectNotFoundException.class javax.ejb.PostActivate.class javax.ejb.PrePassivate.class javax.ejb.Remote.class javax.ejb.RemoteHome.class javax.ejb.Remove.class javax.ejb.RemoveException....
3.hibernate的配置文件(hibernate.cfg.xml)得存在 4.POJO.hbm.xml文件存在 5.hibernate的jar包以及数据库的驱动包存在 Hibernate的编程: 1.构建Configuration对象读取配置文件 2.读取映射文件 3.构建SessionFactory...
相关推荐
Hibernate Session中的 flush方法的作用 ...load方式检索不到的话会抛出org.hibernate.ObjectNotFoundException异常 get方法检索不到的话会返回null 2.从检索执行机制上对比: get方法和find方法都是直接从数据库中检索
javax.ejb.ObjectNotFoundException.class javax.ejb.RemoveException.class javax.ejb.SessionBean.class javax.ejb.SessionContext.class javax.ejb.SessionSynchronization.class javax.ejb.TimedObject.class ...
//该方法会延迟加载/获取数据(只有使用该对象中的字段时才会向数据库发出查询语句),该方法会在内部和二级缓存中查找数据,当数据库中没有要查询的数据时报ObjectNotFoundException异常 (7).createQuery(String HQL)...
javax.ejb.ObjectNotFoundException.class javax.ejb.PostActivate.class javax.ejb.PrePassivate.class javax.ejb.Remote.class javax.ejb.RemoteHome.class javax.ejb.Remove.class javax.ejb.RemoveException....
javax.ejb.ObjectNotFoundException.class javax.ejb.PostActivate.class javax.ejb.PrePassivate.class javax.ejb.Remote.class javax.ejb.RemoteHome.class javax.ejb.Remove.class javax.ejb.RemoveException....
javax.ejb.ObjectNotFoundException.class javax.ejb.PostActivate.class javax.ejb.PrePassivate.class javax.ejb.Remote.class javax.ejb.RemoteHome.class javax.ejb.Remove.class javax.ejb.RemoveException....
3.hibernate的配置文件(hibernate.cfg.xml)得存在 4.POJO.hbm.xml文件存在 5.hibernate的jar包以及数据库的驱动包存在 Hibernate的编程: 1.构建Configuration对象读取配置文件 2.读取映射文件 3.构建SessionFactory...