我有點用的JavaDoc上Session.load困惑:Hibernate的load()方法對不存在的ID做什麼?
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.
我明白我應該用得到,但我不明白是什麼意思有位大約在需要時進行初始化當使用非標識符方法時。
對我來說,如果我有一門課並且使用load(MyClass.class, NonExistingID)
,然後在返回的實例上輸出getId()
的輸出,它似乎每一次都會自動產生一個帶有NonExistingID
的新實例。爲什麼是這樣?
我只是想明白,是不是一種非識別方法?