You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-user@db.apache.org by Ravi <ra...@intercea.com> on 2005/08/15 17:16:35 UTC
afterLookUp() gets called before initialisation of other objects.
Hello !
We are using OJB 0.9.8 for last two years and now when I upgrade it to OJB
1.0.3, I get nullPointerExceptions in our application.
After de-bugging a bit, I found that the afterLookUp() of
PersistenceBrokerAware objects being called before other objects are
materialised.
Not sure what has changed in this release that is causing this problem.
Can you please help?
Regards
Ravi
---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org
Re: afterLookUp() gets called before initialisation of other objects.
Posted by Armin Waibel <ar...@apache.org>.
Ravi wrote:
>>I can now reproduce your issue.
>>It's "caused" by a feature "query prefetching" added to OJB between
>>version 0.98 and 1.0rcX. I'm not familiar with the source code of this
>>feature. Currently the prefetching of references can only be suppressed
>>by changing class QueryReferenceBroker, set line 75
>>batchRetrieval = false;
>>After this your test should pass.
>>I will add a bug report to jira ASAP.
>
>
> Thanks Armin
>
> I set batchRetrieval to false and my tests pass. Does this significantly
> affect performance?
>
First, it seems you have to set
batchRetrieval = false;
prefetchProxies = false;
(If only batchRetrieval is set 'false', the OJB test-suite doesn't pass)
To tell the truth I don't know. This feature was not implemented by me,
so I don't know about any performance comparison test results.
If I run the OJB test-suite with settings on and off the performance
decrease (for 'off') was between 4-30% (but it's against hsql-in-memory
database, the result for a 'real' DB will be differ).
regards,
Armin
> Regards
>
> Ravi
>
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-user-help@db.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org
Re: afterLookUp() gets called before initialisation of other objects.
Posted by Jakob Braeuchi <jb...@gmx.ch>.
hi all,
ojb-68 is fixed in trunk and branch
jakob
Jakob Braeuchi schrieb:
> hi ravi, armin,
>
> i'm working on this issue. see http://issues.apache.org/jira/browse/OJB-68
> i delay firing of lifeCycleEvents until the retrivalTasks are executed.
>
> jakob
>
> Ravi schrieb:
>
>> Armin Waibel <arminw <at> apache.org> writes:
>>
>>
>>> Hi,
>>>
>>> I can now reproduce your issue.
>>> It's "caused" by a feature "query prefetching" added to OJB between
>>> version 0.98 and 1.0rcX. I'm not familiar with the source code of
>>> this feature. Currently the prefetching of references can only be
>>> suppressed by changing class QueryReferenceBroker, set line 75
>>> batchRetrieval = false;
>>> After this your test should pass.
>>> I will add a bug report to jira ASAP.
>>
>>
>>
>> Thanks Armin
>>
>> I set batchRetrieval to false and my tests pass. Does this
>> significantly affect performance?
>>
>> Regards
>>
>> Ravi
>>
>>
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
>> For additional commands, e-mail: ojb-user-help@db.apache.org
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-user-help@db.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org
Re: afterLookUp() gets called before initialisation of other objects.
Posted by Jakob Braeuchi <jb...@gmx.ch>.
hi ravi, armin,
i'm working on this issue. see http://issues.apache.org/jira/browse/OJB-68
i delay firing of lifeCycleEvents until the retrivalTasks are executed.
jakob
Ravi schrieb:
> Armin Waibel <arminw <at> apache.org> writes:
>
>
>>Hi,
>>
>>I can now reproduce your issue.
>>It's "caused" by a feature "query prefetching" added to OJB between
>>version 0.98 and 1.0rcX. I'm not familiar with the source code of this
>>feature. Currently the prefetching of references can only be suppressed
>>by changing class QueryReferenceBroker, set line 75
>>batchRetrieval = false;
>>After this your test should pass.
>>I will add a bug report to jira ASAP.
>
>
> Thanks Armin
>
> I set batchRetrieval to false and my tests pass. Does this significantly
> affect performance?
>
> Regards
>
> Ravi
>
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-user-help@db.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org
Re: afterLookUp() gets called before initialisation of other objects.
Posted by Ravi <ra...@intercea.com>.
Armin Waibel <arminw <at> apache.org> writes:
>
> Hi,
>
> I can now reproduce your issue.
> It's "caused" by a feature "query prefetching" added to OJB between
> version 0.98 and 1.0rcX. I'm not familiar with the source code of this
> feature. Currently the prefetching of references can only be suppressed
> by changing class QueryReferenceBroker, set line 75
> batchRetrieval = false;
> After this your test should pass.
> I will add a bug report to jira ASAP.
Thanks Armin
I set batchRetrieval to false and my tests pass. Does this significantly
affect performance?
Regards
Ravi
---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org
Re: afterLookUp() gets called before initialisation of other objects.
Posted by Armin Waibel <ar...@apache.org>.
Hi,
I can now reproduce your issue.
It's "caused" by a feature "query prefetching" added to OJB between
version 0.98 and 1.0rcX. I'm not familiar with the source code of this
feature. Currently the prefetching of references can only be suppressed
by changing class QueryReferenceBroker, set line 75
batchRetrieval = false;
After this your test should pass.
I will add a bug report to jira ASAP.
regards,
Armin
Armin Waibel wrote:
> Hi Ravi,
>
> I will try to setup a test based on your last post to reproduce your issue.
> Stay tuned!
>
> regards,
> Armin
>
> Ravi wrote:
>
>> 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: ojb-user-unsubscribe@db.apache.org
>> For additional commands, e-mail: ojb-user-help@db.apache.org
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-user-help@db.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org
Re: afterLookUp() gets called before initialisation of other objects.
Posted by Armin Waibel <ar...@apache.org>.
Hi Ravi,
I will try to setup a test based on your last post to reproduce your issue.
Stay tuned!
regards,
Armin
Ravi wrote:
> 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: ojb-user-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-user-help@db.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org
Re: afterLookUp() gets called before initialisation of other objects.
Posted by Ravi <ra...@intercea.com>.
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: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org
Re: afterLookUp() gets called before initialisation of other objects.
Posted by Armin Waibel <ar...@apache.org>.
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.
regards,
Armin
Ravi wrote:
> Hello !
>
> We are using OJB 0.9.8 for last two years and now when I upgrade it to OJB
> 1.0.3, I get nullPointerExceptions in our application.
>
>
>
> After de-bugging a bit, I found that the afterLookUp() of
> PersistenceBrokerAware objects being called before other objects are
> materialised.
>
>
>
> Not sure what has changed in this release that is causing this problem.
>
> Can you please help?
>
>
>
> Regards
>
>
>
> Ravi
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-user-help@db.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org