I'll just chime in here and say that I too have noticed that some of the setters are called after loading from the datastore.
I came across this when I implemented an aspect that pointcut all of the setters. The setters related to reference or collection descriptors were sometimes called after the PersistenceBrokerAware methods. - Cory -----Original Message----- From: news [mailto:[EMAIL PROTECTED] On Behalf Of Ravi Sent: Friday, 19 August 2005 3:35 AM To: ojb-user@db.apache.org Subject: Re: afterLookUp() gets called before initialisation of other objects. Armin Waibel <arminw <at> apache.org> writes: > > Hi Ravi, > > I can't find significant changes between 0.98 and 1.0.x. The main change > is, that the target object of the AfterLookupEvent Object was > immediately nullified after fire the event (because for better > performance OJB reuse the AfterLookupEvent Object and therefore the > target object of the event will be nullified after the "fireEvent" > method return). > > class RsIterator: > // materialize object > ... > // lookup reused event object and set current object as target > getAfterLookupEvent().setTarget(obj); > // fire event > getBroker().fireBrokerEvent(getAfterLookupEvent()); > // nullify the target object to prepare event instance for reuse > getAfterLookupEvent().setTarget(null); > ... > > Thus, if you queue the AfterLookupEvent objects you will run into > problems, e.g. NPE when try to use the target object. In this case you > should store the target object in a separate "queue object" when the > event is fired. Hi Armin Thanks for your response. I am having problem only with batch load. To make it simple, I created two classes TestA and TestB with TestA having reference to TestB and printing TestB's name in afterLookUp(). If I load TestA objects individually by Id using a criteria like below, it works fine and prints TestB's name correctly. Criteria criteria = new Criteria(); criteria.addEqualTo( "id", id ); QueryByCriteria qByCriteria = new QueryByCriteria( TestA.class, criteria ); return broker.getObjectByQuery( qByCriteria ) ); If I do batch load by an empty Criteria like below, I get NullPointerException in afterLookUp() as TestB is null. Criteria criteria = new Criteria(); QueryByCriteria qByCriteria = new QueryByCriteria( TestA.class, criteria ); return broker.getCollectionByQuery( qByCriteria ); Following are the classes and mappings. public class TestA extends OJBDomainImpl implements PersistenceBrokerAware { private TestB testB; private Integer testBId; public TestB getTestB() { return testB; } public void setTestB(TestB testB) { this.testB = testB; } /** * this method is called as the first operation before perform an * object update. */ public void beforeUpdate(PersistenceBroker broker) throws PersistenceBrokerException { } /** * this method is called as the last operation within an update * operation. */ public void afterUpdate(PersistenceBroker broker) throws PersistenceBrokerException { } /** * this method is called as the first operation before perform an * object insert. */ public void beforeInsert(PersistenceBroker broker) throws PersistenceBrokerException { } /** * this method is called as the last operation within an insert * operation. */ public void afterInsert(PersistenceBroker broker) throws PersistenceBrokerException { } /** * this method is called as the first operation within a call to * PersistenceBroker.delete(...). */ public void beforeDelete(PersistenceBroker broker) throws PersistenceBrokerException { } /** * this method is called as the last operation within a call to * PersistenceBroker.delete(...). */ public void afterDelete(PersistenceBroker broker) throws PersistenceBrokerException { } /** * this method is called as the last operation within a call to * PersistenceBroker.getObjectByXXX() or * PersistenceBroker.getCollectionByXXX(). */ public void afterLookup(PersistenceBroker broker) throws PersistenceBrokerException { System.out.println(" Retrieved Test B's name : "+ testB.getName()); } } public class TestB extends OJBDomainImpl { private String name; public String getName() { return name; } public void setName(String name) { this.name = name; } } <class-descriptor class="com.wbbs.model.TestA" table="TEST_A"> <field-descriptor name="id" column="ID" jdbc-type="INTEGER" primarykey="true" autoincrement="true" /> <field-descriptor name="testBId" column="TESTB_ID" jdbc-type="INTEGER" /> <reference-descriptor name="testB" class-ref="com.wbbs.model.TestB" auto-retrieve="true" auto-update="true" auto-delete="false" > <foreignkey field-ref="testBId"/> </reference-descriptor> </class-descriptor> <class-descriptor class="com.wbbs.model.TestB" table="TEST_B"> <field-descriptor name="id" column="ID" jdbc-type="INTEGER" primarykey="true" autoincrement="true" /> <field-descriptor name="name" column="NAME" jdbc-type="VARCHAR" /> </class-descriptor> Same testes work fine with OJB o.98. Please help.. Regards Ravi --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]