You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cayenne.apache.org by Andrey Razumovsky <ra...@gmail.com> on 2008/06/24 12:37:43 UTC

RefreshQuery not supports insert/delete?

Hi!


 I can't figure out how to make the refreshing query work with inserting or
deleting rows in database. For instance:


 Artist a = ...

assert a.getPaintingsArray().size() == 0;


 //here is direct insert into database a painting of artist a (artistid=a.id
)


 RefreshQuery refresher = new RefreshQuery();

context.performGenericQuery(refresher);


 assert a.getPaintingsArray().size() == 1; //that's false



 Everything works perfect when I sql-update in database. When i sql-delete,
i do also get an exception like this:

org.apache.cayenne.FaultFailureException: [v.3.0M4 May 18 2008 16:32:02]
Error resolving fault, no matching row exists in the database for ObjectId:
<ObjectId:Apkforecast, apkforecastid=3>

at org.apache.cayenne.BaseContext.prepareForAccess(BaseContext.java:100)

at com.nic.rainbow.data.auto._Apkforecast.getDate(_Apkforecast.java:29)

...and so on

when i try to iterate through related array


 I'm using ROP if that helps. By the way, when i restart client, the data
becomes correct, so i assume everything has changed correctly on a server.

If that's not supported, can you give me some advice to manually refresh the
desired relationships?


 Thanks,

Andrey

Re: RefreshQuery not supports insert/delete?

Posted by Andrey Razumovsky <ra...@gmail.com>.
Cool, thanks!

2008/6/25, Andrus Adamchik <an...@objectstyle.org>:
>
> Fixed. The fix is very similar to Andrey's, only applied inside Cayenne.
>
> Andrus
>
> On Jun 25, 2008, at 4:26 PM, Andrus Adamchik wrote:
>
> This is a bug. Let me see if there is a quick fix.
>>
>> https://issues.apache.org/cayenne/browse/CAY-1082
>>
>> Andrus
>>
>>
>> On Jun 24, 2008, at 1:37 PM, Andrey Razumovsky wrote:
>>
>> Hi!
>>>
>>>
>>> I can't figure out how to make the refreshing query work with inserting
>>> or
>>> deleting rows in database. For instance:
>>>
>>>
>>> Artist a = ...
>>>
>>> assert a.getPaintingsArray().size() == 0;
>>>
>>>
>>> //here is direct insert into database a painting of artist a (artistid=
>>> a.id
>>> )
>>>
>>>
>>> RefreshQuery refresher = new RefreshQuery();
>>>
>>> context.performGenericQuery(refresher);
>>>
>>>
>>> assert a.getPaintingsArray().size() == 1; //that's false
>>>
>>>
>>>
>>> Everything works perfect when I sql-update in database. When i
>>> sql-delete,
>>> i do also get an exception like this:
>>>
>>> org.apache.cayenne.FaultFailureException: [v.3.0M4 May 18 2008 16:32:02]
>>> Error resolving fault, no matching row exists in the database for
>>> ObjectId:
>>> <ObjectId:Apkforecast, apkforecastid=3>
>>>
>>> at org.apache.cayenne.BaseContext.prepareForAccess(BaseContext.java:100)
>>>
>>> at com.nic.rainbow.data.auto._Apkforecast.getDate(_Apkforecast.java:29)
>>>
>>> ...and so on
>>>
>>> when i try to iterate through related array
>>>
>>>
>>> I'm using ROP if that helps. By the way, when i restart client, the data
>>> becomes correct, so i assume everything has changed correctly on a
>>> server.
>>>
>>> If that's not supported, can you give me some advice to manually refresh
>>> the
>>> desired relationships?
>>>
>>>
>>> Thanks,
>>>
>>> Andrey
>>>
>>
>>
>>
>

Re: RefreshQuery not supports insert/delete?

Posted by Andrus Adamchik <an...@objectstyle.org>.
Fixed. The fix is very similar to Andrey's, only applied inside Cayenne.

Andrus

On Jun 25, 2008, at 4:26 PM, Andrus Adamchik wrote:

> This is a bug. Let me see if there is a quick fix.
>
> https://issues.apache.org/cayenne/browse/CAY-1082
>
> Andrus
>
>
> On Jun 24, 2008, at 1:37 PM, Andrey Razumovsky wrote:
>
>> Hi!
>>
>>
>> I can't figure out how to make the refreshing query work with  
>> inserting or
>> deleting rows in database. For instance:
>>
>>
>> Artist a = ...
>>
>> assert a.getPaintingsArray().size() == 0;
>>
>>
>> //here is direct insert into database a painting of artist a  
>> (artistid=a.id
>> )
>>
>>
>> RefreshQuery refresher = new RefreshQuery();
>>
>> context.performGenericQuery(refresher);
>>
>>
>> assert a.getPaintingsArray().size() == 1; //that's false
>>
>>
>>
>> Everything works perfect when I sql-update in database. When i sql- 
>> delete,
>> i do also get an exception like this:
>>
>> org.apache.cayenne.FaultFailureException: [v.3.0M4 May 18 2008  
>> 16:32:02]
>> Error resolving fault, no matching row exists in the database for  
>> ObjectId:
>> <ObjectId:Apkforecast, apkforecastid=3>
>>
>> at org.apache.cayenne.BaseContext.prepareForAccess(BaseContext.java: 
>> 100)
>>
>> at com.nic.rainbow.data.auto._Apkforecast.getDate(_Apkforecast.java: 
>> 29)
>>
>> ...and so on
>>
>> when i try to iterate through related array
>>
>>
>> I'm using ROP if that helps. By the way, when i restart client, the  
>> data
>> becomes correct, so i assume everything has changed correctly on a  
>> server.
>>
>> If that's not supported, can you give me some advice to manually  
>> refresh the
>> desired relationships?
>>
>>
>> Thanks,
>>
>> Andrey
>
>


Re: RefreshQuery not supports insert/delete?

Posted by Andrus Adamchik <an...@objectstyle.org>.
This is a bug. Let me see if there is a quick fix.

https://issues.apache.org/cayenne/browse/CAY-1082

Andrus


On Jun 24, 2008, at 1:37 PM, Andrey Razumovsky wrote:

> Hi!
>
>
> I can't figure out how to make the refreshing query work with  
> inserting or
> deleting rows in database. For instance:
>
>
> Artist a = ...
>
> assert a.getPaintingsArray().size() == 0;
>
>
> //here is direct insert into database a painting of artist a  
> (artistid=a.id
> )
>
>
> RefreshQuery refresher = new RefreshQuery();
>
> context.performGenericQuery(refresher);
>
>
> assert a.getPaintingsArray().size() == 1; //that's false
>
>
>
> Everything works perfect when I sql-update in database. When i sql- 
> delete,
> i do also get an exception like this:
>
> org.apache.cayenne.FaultFailureException: [v.3.0M4 May 18 2008  
> 16:32:02]
> Error resolving fault, no matching row exists in the database for  
> ObjectId:
> <ObjectId:Apkforecast, apkforecastid=3>
>
> at org.apache.cayenne.BaseContext.prepareForAccess(BaseContext.java: 
> 100)
>
> at com.nic.rainbow.data.auto._Apkforecast.getDate(_Apkforecast.java: 
> 29)
>
> ...and so on
>
> when i try to iterate through related array
>
>
> I'm using ROP if that helps. By the way, when i restart client, the  
> data
> becomes correct, so i assume everything has changed correctly on a  
> server.
>
> If that's not supported, can you give me some advice to manually  
> refresh the
> desired relationships?
>
>
> Thanks,
>
> Andrey


Re: RefreshQuery not supports insert/delete?

Posted by Andrey Razumovsky <ra...@gmail.com>.
Hi Andrus!

I can now see it too, just somewhy it was delivering for more than an hour.
Dev list accepts messages immediately.

I managed to do some workaround. After the refresh, i do:

Collection objects = context.getGraphManager().registeredNodes();
for (Object o : objects)
{
  if (o instanceof Uch)
  {
    ((Uch) o).invalidateProperty(Uch.APKMEASURE_ARRAY_PROPERTY);
  }
  else if ...
}

where "invalidateProperty" is a method in my client entity superclass:
/**
* Marks specified property as a candidate to reload
* @param property Property name
*/
public void invalidateProperty(String property)
{
  EntityResolver resolver = objectContext.getEntityResolver();
  ClassDescriptor descriptor =
resolver.getClassDescriptor(objectId.getEntityName());

  Property propertyDescriptor = descriptor.getProperty(property);
  ValueHolder prop = (ValueHolder)
propertyDescriptor.readPropertyDirectly(this);

  if (prop != null)
  {
    prop.invalidate();
  }
}

That causes property to refetch next time it is addressed. Works fine for
me, but only because i do exactly know what relationships of what entities
can be
modified my side apllication. I'm short of time now, so this
implementation will go.
However, I think, this is a bug.

Andrey

2008/6/24, Andrus Adamchik <an...@objectstyle.org>:
>
>
> On Jun 24, 2008, at 3:36 PM, Andrey Razumovsky wrote:
>
> [Something's wrong with user list]
>>
>
> Andrey,
>
> I saw your message delivered there. I don't think anything is wrong with
> it.
>
> Andrus
>

Re: RefreshQuery not supports insert/delete?

Posted by Andrus Adamchik <an...@objectstyle.org>.
On Jun 24, 2008, at 3:36 PM, Andrey Razumovsky wrote:

> [Something's wrong with user list]

Andrey,

I saw your message delivered there. I don't think anything is wrong  
with it.

Andrus

RefreshQuery not supports insert/delete?

Posted by Andrey Razumovsky <ra...@gmail.com>.
[Something's wrong with user list]

Hi!


I can't figure out how to make the refreshing query work with inserting or
deleting rows in database. For instance:


Artist a = ...

assert a.getPaintingsArray().size() == 0;


//here is direct insert into database a painting of artist a (artistid=a.id)


RefreshQuery refresher = new RefreshQuery();

context.performGenericQuery(refresher);


assert a.getPaintingsArray().size() == 1; //that's false



Everything works perfect when I sql-update in database. When i sql-delete, i
do also get an exception like this:

org.apache.cayenne.FaultFailureException: [v.3.0M4 May 18 2008 16:32:02]
Error resolving fault, no matching row exists in the database for ObjectId:
<ObjectId:Apkforecast, apkforecastid=3>

at org.apache.cayenne.BaseContext.prepareForAccess(BaseContext.java:100)

at com.nic.rainbow.data.auto._Apkforecast.getDate(_Apkforecast.java:29)

...and so on

when i try to iterate through related array


I'm using ROP if that helps. By the way, when i restart client, the data
becomes correct, so i assume everything has changed correctly on a server.

If that's not supported, can you give me some advice to manually refresh the
desired relationships?


Thanks,
Andrey

Re: RefreshQuery not supports insert/delete?

Posted by Andrey Razumovsky <ra...@gmail.com>.
Hi Marcin, thanks for your answer!

I tried with def strategy (NO_CACHE) or SHARED_CACHE - that makes no
difference. But anyways, I definitely want my relationships be
refreshed without any more SelectQueries, i.e. objects in memory be
invalidated automatically.
For sure, b) and с)
will work - this is roughly the same as restarting the client. I
haven't tried a), but this is no better than my workaround because I
need to manually
specify objects for refresh. What I wish is all objects *with their
rels* be refreshed when I perform full
RefreshQuery() [no parameters here].
Still, there's some debate about how this could be done,
because invalidating all rels will greatly decrease performance (I feel this
event if I manually invalidate three
ObjRelationships) and otherwise - how to check, which relationshps are
to be invalidated (i.e. which rows were inserted/deleted into
database).
Current client implementation, as long as I understood, just updates already
loaded objects, walking along using visitToOne() and visitToMany() methods.

About your suggestion, definitely I would want to use registeredObjects()
instead of uncommitedObjects(), because I don't know which objects (rels)
were modified behind the scenes. And I really want toMany relationships be
refreshed, so my workaround will go, I only need to make it more generic.

Thanks,
Andrey

2008/6/25, Marcin Skladaniec <ma...@ish.com.au>:
>
> Hi
>
> This was something I reported before , but I cannot find the message
> anymore.
> Are you using caching ? what type ? are you using cache keys ?
>
> Try:
> a) new RefreshQuery(artist)
> b) do a query in new context
> c) do a query in new context with no caching.
>
> In our setup we have overriden the CayenneContext commitChanges and
> performQuery methods.
> The latter attaches cache keys based on the query object, the former
> executes RefreshQuery(String[] cacheKeys) based on uncommittedObjects()
>
> It does help in most occasions, but still getting counts of toMany
> relationships is not refreshed.
>
> Marcin
>
> On Tue, 24 Jun 2008 14:37:43 +0400
>  "Andrey Razumovsky" <ra...@gmail.com> wrote:
>
>> Hi!
>>
>>
>> I can't figure out how to make the refreshing query work with inserting or
>> deleting rows in database. For instance:
>>
>>
>> Artist a = ...
>>
>> assert a.getPaintingsArray().size() == 0;
>>
>>
>> //here is direct insert into database a painting of artist a (artistid=
>> a.id
>> )
>>
>>
>> RefreshQuery refresher = new RefreshQuery();
>>
>> context.performGenericQuery(refresher);
>>
>>
>> assert a.getPaintingsArray().size() == 1; //that's false
>>
>>
>>
>> Everything works perfect when I sql-update in database. When i sql-delete,
>> i do also get an exception like this:
>>
>> org.apache.cayenne.FaultFailureException: [v.3.0M4 May 18 2008 16:32:02]
>> Error resolving fault, no matching row exists in the database for
>> ObjectId:
>> <ObjectId:Apkforecast, apkforecastid=3>
>>
>> at org.apache.cayenne.BaseContext.prepareForAccess(BaseContext.java:100)
>>
>> at com.nic.rainbow.data.auto._Apkforecast.getDate(_Apkforecast.java:29)
>>
>> ...and so on
>>
>> when i try to iterate through related array
>>
>>
>> I'm using ROP if that helps. By the way, when i restart client, the data
>> becomes correct, so i assume everything has changed correctly on a server.
>>
>> If that's not supported, can you give me some advice to manually refresh
>> the
>> desired relationships?
>>
>>
>> Thanks,
>>
>> Andrey
>>
>
>

Re: RefreshQuery not supports insert/delete?

Posted by Marcin Skladaniec <ma...@ish.com.au>.
Hi

This was something I reported before , but I cannot find 
the message anymore.
Are you using caching ? what type ? are you using cache 
keys ?

Try:
a) new RefreshQuery(artist)
b) do a query in new context
c) do a query in new context with no caching.

In our setup we have overriden the CayenneContext 
commitChanges and performQuery methods.
The latter attaches cache keys based on the query object, 
the former executes RefreshQuery(String[] cacheKeys) based 
on uncommittedObjects()

It does help in most occasions, but still getting counts 
of toMany relationships is not refreshed.

Marcin

On Tue, 24 Jun 2008 14:37:43 +0400
  "Andrey Razumovsky" <ra...@gmail.com> wrote:
> Hi!
> 
> 
> I can't figure out how to make the refreshing query work 
>with inserting or
> deleting rows in database. For instance:
> 
> 
> Artist a = ...
> 
> assert a.getPaintingsArray().size() == 0;
> 
> 
> //here is direct insert into database a painting of 
>artist a (artistid=a.id
> )
> 
> 
> RefreshQuery refresher = new RefreshQuery();
> 
> context.performGenericQuery(refresher);
> 
> 
> assert a.getPaintingsArray().size() == 1; //that's false
> 
> 
> 
> Everything works perfect when I sql-update in database. 
>When i sql-delete,
> i do also get an exception like this:
> 
> org.apache.cayenne.FaultFailureException: [v.3.0M4 May 
>18 2008 16:32:02]
> Error resolving fault, no matching row exists in the 
>database for ObjectId:
> <ObjectId:Apkforecast, apkforecastid=3>
> 
> at 
>org.apache.cayenne.BaseContext.prepareForAccess(BaseContext.java:100)
> 
> at 
>com.nic.rainbow.data.auto._Apkforecast.getDate(_Apkforecast.java:29)
> 
> ...and so on
> 
> when i try to iterate through related array
> 
> 
> I'm using ROP if that helps. By the way, when i restart 
>client, the data
> becomes correct, so i assume everything has changed 
>correctly on a server.
> 
> If that's not supported, can you give me some advice to 
>manually refresh the
> desired relationships?
> 
> 
> Thanks,
> 
> Andrey