google-code-export / objectify-appengine

Automatically exported from code.google.com/p/objectify-appengine
MIT License
1 stars 0 forks source link

Ignored values loaded from the cache #226

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Create entity with an @Ignore field with a default value.
For example boolean x = false;
2. Change the value of the ignored field
3. Save the entity
4. Load the entity again from the cache and the value = the updated value 
rather than the constructor's default value.

What is the expected output? What do you see instead?
I'd expect all ignored properties to resort to the default value from the 
constructor rather than keeping their last value when loaded.

What version of the product are you using? On what operating system?
5.1.1

If whole entities are being cached I understand that it's not efficient to 
recreate a new instance to set default values so maybe clearer documentation or 
a method that can be annotated with @PseduoConstructor that will be called when 
an instance is reloaded from the cache?

Original issue reported on code.google.com by will.cal...@gmail.com on 17 Nov 2014 at 2:05

GoogleCodeExporter commented 9 years ago
The session cache is well-documented:

https://code.google.com/p/objectify-appengine/wiki/Caching

Original comment by lhori...@gmail.com on 17 Nov 2014 at 2:33

GoogleCodeExporter commented 9 years ago
I agree the session cache is (fairly) well documented, but nowhere I've seen 
does it spell out the fact that ignored fields will be reloaded in their 
previous state and are therefore not ignored when an instance is loaded from 
the cache.

Inconsistent behaviour when loading an entity depending on whether it's loaded 
from the datastore or a cache is asking for trouble as where it's loaded from 
is not clear to the developer.

Original comment by will.cal...@gmail.com on 17 Nov 2014 at 2:40

GoogleCodeExporter commented 9 years ago
Nothing is being reloaded from state. You are getting the *same* object back, 
as documented. Objectify does not mangle your object instances. What do you 
expect to happen?

Original comment by lhori...@gmail.com on 17 Nov 2014 at 2:57

GoogleCodeExporter commented 9 years ago
I understand what you're saying, but when I first noticed this I expected that 
when I called .load() that ignored properties would not be loaded.

It would be ideal if calling load exhibited the same behaviour no matter where 
an entity is loaded from, surely you can't disagree with that? There are 
several options:

1. The tidiest but least efficient option would be to create a new instance of 
the object and copy un-ignored values across to the new instance.

2. Have some kind of hacky but well documented workaround where an alternative 
method can be called on the object on load to developers can set up whatever 
they need to using that.

I understand there's no quick fix here. I'm not going to pretend it's a major 
issue as it's fairly easy to work around, but imo it is a bug when you can't 
predict how an application will behave when you make a method call.

Original comment by will.cal...@gmail.com on 17 Nov 2014 at 3:06

GoogleCodeExporter commented 9 years ago
No.

There are myriad reasons why a session cache returns same object instances, 
many of which were hashed out on the Objectify mailing list when the session 
cache was instituted. JPA and JDO sessions both work the same way, and, having 
written applications with both approaches, I can quite firmly say that 
Objectify's current behavior is "correct".

Original comment by lhori...@gmail.com on 17 Nov 2014 at 9:26