问题
Could somebody explain what does PersistenceUtil.isLoaded returns in the context of JPA and hibernate. My impression was that it identifies if the value is loaded and can be accessed without database access. But recently I came upon a case that PesistenceUtil.isLoaded returns true, while the object is an instance of HibernateProxy, and any access to it throws a LIE. I would appreciate any comments.
回答1:
Method isLoaded in PersistenceUtil checks is entity loaded. Entity being loaded means that all eager attributes are loaded from database or assigned by application. In JPA 2.0 specification this is told with following words:
An entity is considered to be loaded if all attributes with FetchType.EAGER—whether explictly specified or by default—(including relationship and other collection-valued attributes) have been loaded from the database or assigned by the application. Attributes with FetchType.LAZY may or may not have been loaded.
For detailed explanation, please refer to JPA 2.0 specification, 3.2.9 Load State.
来源:https://stackoverflow.com/questions/10437552/what-does-persistenceutil-isloaded-means