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;

你可能感兴趣的:(Hibernate,Java,.net)