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 ol...@ppi.de on 2003/03/17 15:40:08 UTC

query for null reference (= foreign key) fields

Hello,

I have observed a behaviour in the PB query engine which
could be improved in my opinion.

I have a persistence-capable class 'Node' with a reference 
'parentNode' of type 'Node' (suitable to build a tree).

As usual with OJB, there is a (private) field 'parentNode_refid'
whose type corresponds to the primary key of class Node.  (long 
in my case.)  Here is a excerpt from my repository.xml: 

<field-descriptor name="parentNode_refid" ... />
<reference-descriptor name="parentNode" class-ref="Node">
  <foreignkey field-ref="parentNode_refid"/>
</reference-descriptor>

I want to formulate a query for all nodes that do not
have a parent node.  What I consider canaconical from the
documentation was:

criteria.addIsNull("parentNode"); // does not work

But that does not work.  Unfortunately, I does not through
an exception either.  The query will just return no objects.

What I have to write is:

    crit.addEqualTo("parentNode_refid", new Integer(0));

which is somewhat ugly because it uses the "secret" auxiliary
reference which I would like to hide from the developer.
(It is no big deal for our project because we have a 
layer on top of OJB where I can easily hide this.)

What do you think?

Olli


-- 
  Oliver Matz
  ppi Media GmbH
  Deliusstraße 10
  D-24114 Kiel
  phone	+49 (0) 43 1-53 53-422
  fax     	+49 (0) 43 1-53 53-2 22
  email	mailto:oliver.matz@ppi.de
  web	www.ppi.de


RE: query for null reference (= foreign key) fields

Posted by Theo Niemeijer <th...@juras.org>.
I agree, that does not look nice.
However, as far as i know your example should work, at
least it does for me.  Granted, I still use field id's instead of
field names, but that should not make a difference I think ?
Have you looked at the generated SQL for a clue about what
went wrong ?

Cheers,
	Theo




> -----Oorspronkelijk bericht-----
> Van: oliver.matz@ppi.de [mailto:oliver.matz@ppi.de]
> Verzonden: maandag 17 maart 2003 15:40
> Aan: ojb-user@db.apache.org
> Onderwerp: query for null reference (= foreign key) fields
>
>
> Hello,
>
> I have observed a behaviour in the PB query engine which
> could be improved in my opinion.
>
> I have a persistence-capable class 'Node' with a reference
> 'parentNode' of type 'Node' (suitable to build a tree).
>
> As usual with OJB, there is a (private) field 'parentNode_refid'
> whose type corresponds to the primary key of class Node.  (long
> in my case.)  Here is a excerpt from my repository.xml:
>
> <field-descriptor name="parentNode_refid" ... />
> <reference-descriptor name="parentNode" class-ref="Node">
>   <foreignkey field-ref="parentNode_refid"/>
> </reference-descriptor>
>
> I want to formulate a query for all nodes that do not
> have a parent node.  What I consider canaconical from the
> documentation was:
>
> criteria.addIsNull("parentNode"); // does not work
>
> But that does not work.  Unfortunately, I does not through
> an exception either.  The query will just return no objects.
>
> What I have to write is:
>
>     crit.addEqualTo("parentNode_refid", new Integer(0));
>
> which is somewhat ugly because it uses the "secret" auxiliary
> reference which I would like to hide from the developer.
> (It is no big deal for our project because we have a
> layer on top of OJB where I can easily hide this.)
>
> What do you think?
>
> Olli
>
>
> --
>   Oliver Matz
>   ppi Media GmbH
>   Deliusstraße 10
>   D-24114 Kiel
>   phone	+49 (0) 43 1-53 53-422
>   fax     	+49 (0) 43 1-53 53-2 22
>   email	mailto:oliver.matz@ppi.de
>   web	www.ppi.de
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-user-help@db.apache.org
>
>