任何人都可以對我有什麼這兩個代碼之間的區別:什麼是在休眠query.uniqueResult()VS session.load之間的差異
Session session = getSession() ; // this method check if there is an open session return it if it's not open a new session
Query query =session.createQuery("from Entity e where e.id=1");
Entity object = (Entity)query.uniqueResult();
和驗證碼:
Session session = getSession() ; // this method check if there is an open session return it if it's not open a new session
Entity object = (Entity)session.load(Entity.class, new Integer(1));
做的第一種方法返回一個代理對象?如果我再次調用它是否會觸發數據庫?
可能重複[在Hibernate中load()vs get()的優點是什麼?](http://stackoverflow.com/questions/5370482/whats-the-advantage-of-load-vs-get在休眠) – Azodious
這不是確切的重複,但接受的答案也回答你的問題。 – Azodious
@有趣的是它不是關於query.uniqueResual()它是關於session.get()我認爲他們有不同的行爲 –