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 Reda Benzair <re...@smartjog.com> on 2003/12/29 10:24:57 UTC

[detail] reload Object ? ? (Problem Cache)

You're right. Sorry.

The third line is the one I get after I call pb.clearCache(). And it's
the one I would rather get instead of line 2.

Something I noticed since I posted this message : This sample code works
great if the query concerns "classical" classes instead of Employee :
Employee is an extent.

<class-descriptor class="sj.employee.bean.Employee">
	<extent-class class-ref="sj.employee.bean.EmployeeImpl"/>
	<extent-class class-ref="sj.employeeRh.bean.EmployeeRhImpl"/>
	<extent-class class-ref="sj.employeeBr.bean.EmployeeBrImpl"/>
	<extent-class
class-ref="sj.employeeRhBr.bean.EmployeeRhBrImpl"/>
</class-descriptor>
<class-descriptor class="sj.employee.bean.EmployeeImpl"
table="EMPLOYEE">
	<!-- .............. -->
</class-descriptor>
<!-- .............. -->
<class-descriptor class="sj.employee.bean.EmployeeRhBr">
	<extent-class
class-ref="sj.employeeRhBr.bean.EmployeeRhBrImpl"/>
</class-descriptor>
<class-descriptor class="sj.employee.bean.EmployeeRhBrImpl"
table="EMPLOYEE">
	<!-- .............. -->
</class-descriptor>

=> If I create a new Identity(employee505, pb), the resulting object
does not match (.equals + .hascode) the one that already exists in the
cache : removeFromCache has no effect, wich explains the strange
behaviour above. As a workaround, I have removed all extents from my
repository but it's a shame...

What should I do?


-----Original Message-----
From: Armin Waibel [mailto:armin@code-au-lait.de] 
Sent: mardi 23 décembre 2003 01:42
To: OJB Users List
Subject: Re: reload Object ? ? (Problem Cache)

Hi,

in your example only 2 System.out.println(..) lines performed, but 3 
lines are printed?! Do you forget one println() statement?

regards,
Armin

Reda Benzair wrote:
> Hi all,
> 
>  
> 
> I have a -simple?- question about OJB cache:
> 
>  
> 
> How can I force refreshing an object? Typically is there a method like

> PB.refreshObject(Object o)? -I know of course this one doesn't
exist...-
> 
>  
> 
> To be more precise, I have someting like this:
> 
> PersistenceBroker pb = 
> PersistenceBrokerFactory.createPersistenceBroker("jcd", "user",
"pass");
> Criteria crit = new Criteria();
> crit.addEqualTo("Id", new Integer(505));
> Employee employee505 = (Employee) pb.getObjectByQuery(new 
> QueryByCriteria(Employee.class, crit));
> 
> System.out.println("ID 505 = " + employee505.getName() + " " + 
> employee505);
> 
> employee505.setName("MODIFIED " + employee505.getName());
> // modified but not stored... should be erased by remove + reload?
> pb.removeFromCache(employee505);
> employee505 = (Employee) pb.getObjectByQuery(new
> QueryByCriteria(Employee.class, crit));
> 
> System.out.println("505 = " + employee505.getName() + " " + 
> employee505);
> 
 >
 >
> The standard output is:
> 
> 505 = John Doe sj.employeeRhBr.bean.EmployeeRhBrImpl@e33e18
> 
> 505 = MODIFIED john Doe sj.employeeRhBr.bean.EmployeeRhBrImpl@e33e18
> 
> 505 = John Doe sj.employeeRhBr.bean.EmployeeRhBrImpl@48f675
> 
> And I would have liked line2 to be exactly equal to line1. Where am I 
> wrong?
> 
>  
> 
> Thank you very much by advance, since this blocks my team on the 
> production environment...
> 
>  
> 
> 



---------------------------------------------------------------------
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: [detail] reload Object ? ? (Problem Cache)

Posted by Armin Waibel <ar...@code-au-lait.de>.
Hi,

 >>How can I force refreshing an object? Typically is there a method like
 >>PB.refreshObject(Object o)? -I know of course this one doesn't
 >
 > exist...-

yes, you only can perform a refresh operation on the references.
If you remove an object from the cache, next time you lookup the same 
object (same Identity/PK) OJB materialize a new object instance.

Reda Benzair wrote:
> You're right. Sorry.
> 
> The third line is the one I get after I call pb.clearCache(). And it's
> the one I would rather get instead of line 2.
> 
I add a similar test case to test suite (see 
...broker.ObjectCacheTest#testObjectCacheDefaultImpl in CVS). This test 
pass without any problems. If the object was removed from cache, the 
object was read from the DB.

> Something I noticed since I posted this message : This sample code works
> great if the query concerns "classical" classes instead of Employee :
> Employee is an extent.
>

hmm, seems to be an Identity problem. In OJB Identity class two objects 
are equals
a) if they had the same TopLevelClass (in your case interface Employee)
b) and the same PK values (don't know what the PK fields of your 
Employee implementation classes are)

I think your "extent-class declaration" cause the problem (Or OJB's 
handling of extent clases).
EmployeeRhBr is an interface that extends Employee interface?
EmployeeRhBrImpl is an extent of Employee AND EmployeeRhBr. Why?
Maybe this cause the problem.

regards,
Armin

> <class-descriptor class="sj.employee.bean.Employee">
> 	<extent-class class-ref="sj.employee.bean.EmployeeImpl"/>
> 	<extent-class class-ref="sj.employeeRh.bean.EmployeeRhImpl"/>
> 	<extent-class class-ref="sj.employeeBr.bean.EmployeeBrImpl"/>
> 	<extent-class
> class-ref="sj.employeeRhBr.bean.EmployeeRhBrImpl"/>
> </class-descriptor>
> <class-descriptor class="sj.employee.bean.EmployeeImpl"
> table="EMPLOYEE">
> 	<!-- .............. -->
> </class-descriptor>
> <!-- .............. -->
> <class-descriptor class="sj.employee.bean.EmployeeRhBr">
> 	<extent-class
> class-ref="sj.employeeRhBr.bean.EmployeeRhBrImpl"/>
> </class-descriptor>
> <class-descriptor class="sj.employee.bean.EmployeeRhBrImpl"
> table="EMPLOYEE">
> 	<!-- .............. -->
> </class-descriptor>
> 
> => If I create a new Identity(employee505, pb), the resulting object
> does not match (.equals + .hascode) the one that already exists in the
> cache : removeFromCache has no effect, wich explains the strange
> behaviour above. As a workaround, I have removed all extents from my
> repository but it's a shame...
> 
> What should I do?
> 
> 
> -----Original Message-----
> From: Armin Waibel [mailto:armin@code-au-lait.de] 
> Sent: mardi 23 décembre 2003 01:42
> To: OJB Users List
> Subject: Re: reload Object ? ? (Problem Cache)
> 
> Hi,
> 
> in your example only 2 System.out.println(..) lines performed, but 3 
> lines are printed?! Do you forget one println() statement?
> 
> regards,
> Armin
> 
> Reda Benzair wrote:
> 
>>Hi all,
>>
>> 
>>
>>I have a -simple?- question about OJB cache:
>>
>> 
>>
>>How can I force refreshing an object? Typically is there a method like
> 
> 
>>PB.refreshObject(Object o)? -I know of course this one doesn't
> 
> exist...-
> 
>> 
>>
>>To be more precise, I have someting like this:
>>
>>PersistenceBroker pb = 
>>PersistenceBrokerFactory.createPersistenceBroker("jcd", "user",
> 
> "pass");
> 
>>Criteria crit = new Criteria();
>>crit.addEqualTo("Id", new Integer(505));
>>Employee employee505 = (Employee) pb.getObjectByQuery(new 
>>QueryByCriteria(Employee.class, crit));
>>
>>System.out.println("ID 505 = " + employee505.getName() + " " + 
>>employee505);
>>
>>employee505.setName("MODIFIED " + employee505.getName());
>>// modified but not stored... should be erased by remove + reload?
>>pb.removeFromCache(employee505);
>>employee505 = (Employee) pb.getObjectByQuery(new
>>QueryByCriteria(Employee.class, crit));
>>
>>System.out.println("505 = " + employee505.getName() + " " + 
>>employee505);
>>
> 
>  >
>  >
> 
>>The standard output is:
>>
>>505 = John Doe sj.employeeRhBr.bean.EmployeeRhBrImpl@e33e18
>>
>>505 = MODIFIED john Doe sj.employeeRhBr.bean.EmployeeRhBrImpl@e33e18
>>
>>505 = John Doe sj.employeeRhBr.bean.EmployeeRhBrImpl@48f675
>>
>>And I would have liked line2 to be exactly equal to line1. Where am I 
>>wrong?
>>
>> 
>>
>>Thank you very much by advance, since this blocks my team on the 
>>production environment...
>>
>> 
>>
>>
> 
> 
> 
> 
> ---------------------------------------------------------------------
> 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