Can anyone tell me what's the difference between this code:
// This following method checks if there is an open session
// and if yes - returns it, if not - opens a new session.
Session session = getSession();
Query query = session.createQuery("from Entity e where e.id = 1");
Entity object = (Entity)query.uniqueResult();
and this:
Session session = getSession();
Entity object = (Entity)session.load(Entity.class, new Integer(1));
Does the first method return a proxy object? And if I call it again does it hit the database?
There are some differences (as of Hibernate 5.2.6).
session.load()
query.uniqueResult()
null
if the query returns no results.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.