-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Interceptor.onload and checking state laziness
PostPosted: Wed Apr 04, 2012 4:01 am 
Newbie

Joined: Thu Jan 13, 2005 4:04 am
Posts: 12
Location: Estonia
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.