Hibernate:get()和load()的区别

调试如下:

1、load()

log.debug("------------------");;
ProductDictate dictate = (ProductDictate);session.load(ProductDictate.class, new Long(100););;
log.debug("+++++++++++"+dictate);;

运行错误如下:

[debug] :--------------------
net.sf.hibernate.ObjectNotFoundException: No row with the given identifier exists: 44, of class: com.norteksoft.thiebaut.worksheet.model.ProductDictate

at net.sf.hibernate.ObjectNotFoundException.throwIfNull(ObjectNotFoundException.java:24);

at net.sf.hibernate.impl.SessionImpl.load(SessionImpl.java:1921);



2、get()

log.debug("------------------");;
ProductDictate dictate = (ProductDictate);session.get(ProductDictate.class, new Long(100););;
log.debug("+++++++++++"+dictate);;


运行结果如下:

[debug] :------------------
[debug] :+++++++++++null


用get()方法没有找到对象的时候返回null,而没有报强制类型转换错误是因为如下写法是允许的:

Object a = (Object); null;
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值