Re: How to check for null values when using proxies?
Armin Waibel <[email protected]> Fri, 15 Feb 2008 02:05:58 +0100
| Newsgroups | gmane.comp.jakarta.ojb.user |
|---|---|
| Message-ID | <[email protected]> |
Hi,
Schmidt wrote:
> Hi,
>
> Consider that an object A has an association with an object B. Also that
> dynamic proxies are in use so that when object A is loaded, a proxy to B is
> created and the object B itself is not materialized. Sometimes, before
> taking an action, I need to verify if there is a B object associated to A.
> This check is done as follows:
> if (a.getB() == null) {...}
>
> The problem is that even if there isn't a B associated with A, OJB returns
> false because there is always a proxy between A and B. The check is actually
> done using the proxy reference which is always present.
> How can we handle that?
>
Which version of OJB do you use? I try to reproduce this with the
current source (OJB_1_0_RELEASE branch) without success. If class
Article has a 1:1 relation to ProductGroup and I search for an Article
without a ProductGroup I get:
Criteria c = new Criteria().addEqualTo("articleName", name + "without PG");
q = QueryFactory.newQuery(ArticleWithReferenceProxy.class, c);
Article br = (ArticleWithReferenceProxy) broker.getObjectByQuery(q);
assertNotNull(br);
assertNull(br.getProductGroup());
Could it be that the association between A and B is a 1:n relation?
regards,
Armin
> Thank in advance!