Clear xData object instance cache

Hi,

I get couple of difficulties to manage several objects and relations with having error about
"The object is already in persistent context"
To avoid that I tried to use
xDataServerContainer.AureliusManager.Evict(<object_instance>)
If it improves processes, it isn't a full success.

Is there a way to clear FULL cache of ALL object instance inside AureliusManager at end of process of a service implementation in order not to be disturbed with a new method is call (as it happens currently for me)?

Thanks for help

Sylvain

Avoid Evict. It's seldom necessary. My piece of advice is that you should only use it if you are 100% sure you need it and certain about what's going on. If you don't, then you probably shouldn't be using it.

I'd rather recommend that you understand why you are getting such message, and then solve the logic to avoid it. That message happens when you try to persist two different instances of the "same entity" - by "same entity" I mean the same class with the same id (e.g., two instances of a customer with id 10).

What do you mean by a "new method is call"? XData is stateless, each request, each service operation method invocation has its own manager with its own objects.

I suggest you provide the specific issues you are having and solve them case by case.

Hi Wagner
Thanks for reply
In fact inside same xdata server I get functions for own service implementation and I'm using a model of several objects with relations at different depths.
Each service implementation is using several request like

Product := TXDataOperationContext.Current.GetManager.Find<TProduct>.Where(TLinq.Eq('product_name', nametosearch)).UniqueResult;

And when a I call a first time function everything is working fine.
But when I'm calling the same function (or other using similar object) often I get this famous ""The object is already in persistent context"
As you mention it's quite logic as AureliusManager is requested to integrate to instance of same objects with same id, from direct relation or in depth relation (level 2 or more).

But if I'm calling TXDataOperationContext.Current.GetManager on all function I guess I keep the same AureliusManager so with already know instances
That's why I'm requesting it to forget instance by "evict"
Do I create specific Manager instance inside each function to be sure there won't be conflicts ?

TXDataOperationContext.Current.CreateManager

No need to create specific manager instance. You should usually use the one provided by XData.
The problem is simply in the way you are handling your objects. The error happens when you update objects, not when you retrieve (Find). Please try to provide a minimal case with code and then we can analyze what's going on for that case.

Hi Wagner
I have to check because I think a made an error
I was using probably 2 differents manager without creating one
One when retreiving objects like

Product := TXDataOperationContext.Current.GetManager.Find<TProduct>.Where(TLinq.Eq('product_name', nametosearch)).UniqueResult;

and another one when changing content in DB

xDataServerContainer.AureliusManager.SaveOrUpdate(New_Product);

I have to check if behavior is more stable using the same like

TXDataOperationContext.Current.GetManager.SaveOrUpdate(New_Product);

Thanks

1 Like