You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@isis.apache.org by Nobby Knox <No...@ecn.co.za> on 2014/11/21 13:26:47 UTC

Finding entities with JDOQL using cached entities

Hi everyone,


I'm tying to implement a filter in a JDOQL query using a cached entity in the where clause, but I'm having some trouble. Here is a quick run down of my domain models:


<< Owner >>

+ name

+ etc


<< Pet >>

+ name

+ Owner  (<- Owner model from above)


In my Pet domain model I have a reference to the Owner object, which I cache in order to implement future filtering. The problem is that the original Owner object seems to be some kind of proxy for the actual Owner object. When I save the object in the cache, something weird happens and the properties are set to null.


Is there a way to use a simple POJO (not the enhanced proxy object) in the where clause in order to implement the filter? Maybe there is another way to do this? Should I be looking at caching the actual ID (integer value) and changing the where to something like: where owner_id_OID = :cachedId


I hope this makes sense.


?Kind regards,

Nobby


Nobby Knox
Senior Developer


[http://static.ecntelecoms.za.net/images/ecn-logo.png]

Unit 10 Growthpoint Business Park
2 Tonnetti Street, Midrand, 1685
Office: +27 10 590 6843
Cell: +27 82 459 1604

nobby@ecn.co.za
www.ecn.co.za<http://www.ecn.co.za/>


 This email is sent subject to the terms and conditions detailed in the ECN Email Disclaimer<http://www.nashuacommunications.com/disclaimer-and-confidentiality-note/>

Disclaimer

The information contained in this communication from the sender is confidential. It is intended solely for use by the recipient and others authorized to receive it. 
If you are not the recipient, you are hereby notified that any disclosure, copying, distribution or taking action in relation of the contents of this information is strictly prohibited and may be unlawful.

This email has been scanned for viruses and malware.

RE: Finding entities with JDOQL using cached entities

Posted by Nobby Knox <no...@ecn.co.za>.
Hi Dan,

Thank you very much for your detailed and insightful reply. The bookmark 
service sounds exactly like what I'm looking for. Also, thanks for the 
explanation regarding the DataNucleus enhancer. It now makes much more 
sense.

Kind regards,
Nobby
________________________________________
From: Dan Haywood <da...@haywood-associates.co.uk>
Sent: 21 November 2014 06:12 PM
To: users
Subject: Re: Finding entities with JDOQL using cached entities

On 21 November 2014 13:26, Nobby Knox <No...@ecn.co.za> wrote:

> Hi everyone,
>
>
> I'm tying to implement a filter in a JDOQL query using a cached entity in
> the where clause, but I'm having some trouble. Here is a quick run down of
> my domain models:
>
>
> << Owner >>
>
> + name
>
> + etc
>
>
> << Pet >>
>
> + name
>
> + Owner  (<- Owner model from above)
>
>
> In my Pet domain model I have a reference to the Owner object, which I
> cache in order to implement future filtering. The problem is that the
> original Owner object seems to be some kind of proxy for the actual Owner
> object.


It's not a proxy, instead the DataNucleus enhancer modifies the bytecode.
There's a simplified description on the Apache JDO website [1].




> When I save the object in the cache, something weird happens and the
> properties are set to null.
>
>
That happens when the request (ie JDO persistence session) completes.  JDO
itself does have various support to allow entities to be detached [2], but
we don't surface that as API within Isis




>
> Is there a way to use a simple POJO (not the enhanced proxy object) in the
> where clause in order to implement the filter? Maybe there is another way
> to do this? Should I be looking at caching the actual ID (integer value)
> and changing the where to something like: where owner_id_OID = :cachedId
>
>

Basically, yes, you need to store the identifier for the pojo.  One way to
do that (in a very general way) is to use Isis' BookmarkService [3]; use
BookmarkService#bookmarkFor(...) to obtain a serializable Bookmark, and
BookmarkService#lookup to convert back to the pojo.


HTH

Cheers
Dan

[1] http://db.apache.org/jdo/enhancement.html
[2] https://db.apache.org/jdo/attach_detach.html
[3] http://isis.apache.org/reference/services/bookmark-service.html



>
> I hope this makes sense.
>
>
> ?Kind regards,
>
> Nobby
>
>
> Nobby Knox
> Senior Developer
>
>
> [http://static.ecntelecoms.za.net/images/ecn-logo.png]
>
> Unit 10 Growthpoint Business Park
> 2 Tonnetti Street, Midrand, 1685
> Office: +27 10 590 6843
> Cell: +27 82 459 1604
>
> nobby@ecn.co.za
> www.ecn.co.za<http://www.ecn.co.za/>
>
>
>  This email is sent subject to the terms and conditions detailed in the
> ECN Email Disclaimer<
> http://www.nashuacommunications.com/disclaimer-and-confidentiality-note/>
>
> Disclaimer
>
> The information contained in this communication from the sender is
> confidential. It is intended solely for use by the recipient and others
> authorized to receive it.
> If you are not the recipient, you are hereby notified that any disclosure,
> copying, distribution or taking action in relation of the contents of this
> information is strictly prohibited and may be unlawful.
>
> This email has been scanned for viruses and malware.

Disclaimer

The information contained in this communication from the sender is confidential. It is intended solely for use by the recipient and others authorized to receive it. 
If you are not the recipient, you are hereby notified that any disclosure, copying, distribution or taking action in relation of the contents of this information is strictly prohibited and may be unlawful.

This email has been scanned for viruses and malware.


Re: Finding entities with JDOQL using cached entities

Posted by Dan Haywood <da...@haywood-associates.co.uk>.
On 21 November 2014 13:26, Nobby Knox <No...@ecn.co.za> wrote:

> Hi everyone,
>
>
> I'm tying to implement a filter in a JDOQL query using a cached entity in
> the where clause, but I'm having some trouble. Here is a quick run down of
> my domain models:
>
>
> << Owner >>
>
> + name
>
> + etc
>
>
> << Pet >>
>
> + name
>
> + Owner  (<- Owner model from above)
>
>
> In my Pet domain model I have a reference to the Owner object, which I
> cache in order to implement future filtering. The problem is that the
> original Owner object seems to be some kind of proxy for the actual Owner
> object.


It's not a proxy, instead the DataNucleus enhancer modifies the bytecode.
There's a simplified description on the Apache JDO website [1].




> When I save the object in the cache, something weird happens and the
> properties are set to null.
>
>
That happens when the request (ie JDO persistence session) completes.  JDO
itself does have various support to allow entities to be detached [2], but
we don't surface that as API within Isis




>
> Is there a way to use a simple POJO (not the enhanced proxy object) in the
> where clause in order to implement the filter? Maybe there is another way
> to do this? Should I be looking at caching the actual ID (integer value)
> and changing the where to something like: where owner_id_OID = :cachedId
>
>

Basically, yes, you need to store the identifier for the pojo.  One way to
do that (in a very general way) is to use Isis' BookmarkService [3]; use
BookmarkService#bookmarkFor(...) to obtain a serializable Bookmark, and
BookmarkService#lookup to convert back to the pojo.


HTH

Cheers
Dan

[1] http://db.apache.org/jdo/enhancement.html
[2] https://db.apache.org/jdo/attach_detach.html
[3] http://isis.apache.org/reference/services/bookmark-service.html



>
> I hope this makes sense.
>
>
> ?Kind regards,
>
> Nobby
>
>
> Nobby Knox
> Senior Developer
>
>
> [http://static.ecntelecoms.za.net/images/ecn-logo.png]
>
> Unit 10 Growthpoint Business Park
> 2 Tonnetti Street, Midrand, 1685
> Office: +27 10 590 6843
> Cell: +27 82 459 1604
>
> nobby@ecn.co.za
> www.ecn.co.za<http://www.ecn.co.za/>
>
>
>  This email is sent subject to the terms and conditions detailed in the
> ECN Email Disclaimer<
> http://www.nashuacommunications.com/disclaimer-and-confidentiality-note/>
>
> Disclaimer
>
> The information contained in this communication from the sender is
> confidential. It is intended solely for use by the recipient and others
> authorized to receive it.
> If you are not the recipient, you are hereby notified that any disclosure,
> copying, distribution or taking action in relation of the contents of this
> information is strictly prohibited and may be unlawful.
>
> This email has been scanned for viruses and malware.