Thursday, 15 April 2010

Hibernate Interceptor onSave and onLoad methods returns null -



Hibernate Interceptor onSave and onLoad methods returns null -

i override hibernate emptyinterceptor capture property fields decorations.

public class myentityinterceptor extends emptyinterceptor need access

fields when before save , when reading. onsave , onload methods below.

entity fields returns null. please allow me know feedback , missing here?

public boolean onload(object entity,serializable id, object[] state,string[] propertynames, type[] types) throws callbackexception{ persistable entity = (persistable) entity; system.out.println("===============>"+entity.getcreatedby());//returns null homecoming true; } public boolean onsave(object entity, serializable id, object[] state, string[] propertynames, type[] types) { if (entity instanceof ipersistable) { ipersistable entity = (ipersistable) entity; system.out.println("created by=================>"+((ipersistable) entity).getcreatedby());//returns null } homecoming (true); }

the onload method called before object initialized.refer api.

http://docs.jboss.org/hibernate/orm/3.2/api/org/hibernate/interceptor.html. entity

empty uninitialized instance of class. reason null output. way

capture properties incorrect. object[] state,string[] propertynames key

parameters should utilize if want deal passing parameters. state comes

list of values , property names represent list of fields. please iterate state[] array ,

then expected values. allow me know if need farther assistance.

hibernate

No comments:

Post a Comment