Hi Manuel,
On Nov 20, 2003, at 5:01 PM, Fehlhammer, Manuel wrote:
> Hi Andrus,
>> If you perform a query and it brings back some of the objects that you
>> have already modified but haven't committed, Cayenne will merge DB
>> changes with your object changes (never overwriting any of your
>> changes). If there is an unmodified cached object in the DataContext,
>> it is fully refreshed using new DB data. This is very reasonable
>> behavior, I guess it should suit your needs.
>>
>> Andrus
>
> does this hold also for new objects? Then I must carefully check my
> usecase... I created an object - registered it with the DataContext
> and then tried to find exactly this object via selectquery (before
> doing commitChanges()), but it wasn't found.
>
> I think this new object should be found because it exists already in
> the current context.
Looks like you have a case with a meaningful PK included in the java
class. Am I right?
This is the only case that won't be handled properly right now. If PK
is not the part of the class and is generated, there simply won't be a
case when you can fetch a record that is the same as a new uncommitted
object.
If my assertion is true, lets find a workaround.
1. First, do you really need to make a PK column a writable object
property? For read only access to object id values you can do something
like object.getObjectId().getValueForAttribute("XYZ"). There are lots
of valid cases when this is unavoidable, just checking that yours is
one of those.
2. Assuming that you do need to have it. Then lets at least make a
smaller time window for this problem. Before creating a new object and
assigning it a value, do a fetch to see if such object is already in
the database. Use fetched object if it exists, create a new one only
if it does not. This approach makes sense to me from the general object
identity idea (outside of Cayenne), and I hope it works for you.
In the meantime, let me think if we can or should handle this
transparently in Cayenne. This will require rewriting ObjectId values
on the fly, and arbitrary changing ObjectId contents can have negative
consequences.
Andrus
This archive was generated by hypermail 2.0.0 : Thu Nov 20 2003 - 17:24:46 EST