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 Edson Carlos Ericksson Richter <ed...@mgrinformatica.com.br> on 2004/03/25 16:28:34 UTC
reference (1:1) and null
Hi!
When retrieving a 1:1..0 mapping using proxies, after counting how many
values has in the table, OJB should set the referenced object to NULL
when counting is 0 (not setting the reference for a proxy that will give
a NPE when trying to call a method).
If the value set is a proxy (event if will never have a value there,
since count is 0) the following statement always goes to else section,
and gives a NPE:
// The following test is always false, because until now,
myReferencedObject is a reference to a proxy.
// But the select count(*) returned 0.
if( myObject.myReferencedObject==null ) {
System.out.println("There is no reference");
} else {
System.out.println("There is reference!");
System.out.println("myObject.myReferencedObject.getId() = " +
myObject.myReferencedObject.getId());
// the previous line will throw a NPE, because when materializing, it
return NULL!!!
}
Is possible to fix this? There is one workaround, map all 1:0..1
mappings as collections and does internal treatment to them, or not use
Proxy for 1:0..1 mappings (that will set value to NULL when there is no
referenced object - as expected).
Thanks,
Edson Richter
---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org