I see really-really weird behavior of my code after I started using proxies. Yes, I have read FAQ and know I should use accessors instead of direct access to the members. But... I just want to understand HOW THIS CAN BE POSSIBLE!
public class Company
{
...
public void test(Company other)
{
System.err.println("---TEST---");
System.err.println("this==other => " + (this == other));
System.err.println("this=" + this + ", this.id=" + id + ", getId()=" + getId());
System.err.println("other=" + other + ", other.id=" + other.id + ", getId()=" + other.getId());
System.err.println("----------");
}
...
}
Somewhere in the test:
Company a = person.getCompany();
and then
a.test(a);
Company mapping specifies "proxy" attribute. So in the test 'a' is an instace of a proxy. The test above outputs
[junit] ---TEST---
[junit] this==other => false
[junit] this=eg.Company@19ecd80, this.id=383, getId()=383
[junit] other=eg.Company@19ecd80, other.id=0, getId()=383
[junit] ------
I can not understand this at all. Why this.id works while other.id does not.
How is it possible (this==other) check return false?
Why should I use accessors in my equals() implementation? Just because second object may not loaded yet or there are other reasons?
|