Hi,
I would like to check property laziness of loaded entity inside onload handler of the entity interceptor but seems that entity and it's states passed to handler Interceptor.onLoad are in the middle of initialization and standard Hibernate.isInitialized() method detects both initialized and noninitialized state properties to be uninitialized. This is probably because entity is "somewhere in the middle of the initialization phase" and it and it's property states are considered all to be uninitialized in the time of onload was invoked. Is there any other way to achieve desired result (detect inside onload which of the lazy ends will be initialized/uninitialized)?
Case description:
Hibernate 3.3.1
Case:
class Parent { @OneToMany(fetch = FetchType.LAZY, mappedBy = "parent") private Set<Child> childs = new HashSet<Child>(0); }
hqlquery: "FROM Parent p LEFT JOIN FETCH p.childs where p.id = :id"
public boolean onLoad(Object entity, Serializable id, Object[] state, String[] propertyNames, Type[] types) throws CallbackException { if (Hibernate.isInitialized(state[index of child set property of the parent])) { // Do something, but never happens for entities loaded by queries like above described. }
API description of the onload handler of the interceptor: Called just before an object is initialized. The interceptor may change the state, which will be propagated to the persistent object. Note that when this method is called, entity will be an empty uninitialized instance of the class.
Returns: true if the user modified the state in any way. Throws: CallbackException
Wbr, Ilhan
|