load和get

参考:hibernate延迟加载(get和load的区别)

Hibernate之load和get的区别

get方法的doc解释:

    /**
* Return the persistent instance of the given entity class with the given identifier,
* or null if there is no such persistent instance. (If the instance is already associated
* with the session, return that instance. This method never returns an uninitialized instance.)
*
* @param entityType The entity type
* @param id an identifier
*
* @return a persistent instance or null
*/
<T> T get(Class<T> entityType, Serializable id);

load方法的doc解释:

    /**
* Return the persistent instance of the given entity class with the given identifier,
* assuming that the instance exists. This method might return a proxied instance that
* is initialized on-demand, when a non-identifier method is accessed.
* You should not use this method to determine if an instance exists (use get()
* instead). Use this only to retrieve an instance that you assume exists, where non-existence
* would be an actual error.
*
* @param theClass a persistent class
* @param id a valid identifier of an existing persistent instance of the class
*
* @return the persistent instance or proxy
*/
<T> T load(Class<T> theClass, Serializable id);
上一篇:根据Email地址跳转到相应的邮箱登录页面 (转)


下一篇:PAT 1026. Table Tennis