impactrudia / objectify-appengine

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

OnSave-Method is not usable to generate Value of @Id annotated Field #208

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
With version 4.1 I used the OnSave feature on the abstract base class of 
entities annotated with @EntitySubClass to generate an unique String key that 
was built from properties of the class. 

More specific, I am trying to store subclasses of the Entity Activity which has 
a DateTime-Property which is unique and I want to use this as Id. What I did 
was to serialize the date to the (private) String property "key" so whenever I 
persist a new activity for the same date the old one gets overwritten 
automatically (intended behavior)

public abstract class Activity {

...

    @Id
    private String key;
    @Index
    private DateTime day;

        @OnSave
    private void generateKey() {
        key = getClass().getName() + "/" + formatter.print(day);
    }
...

}

In Objectify 4.1 this worked great, but after upgrading to 5.x, Objectify if 
the key is set and then throws an exception without calling the OnSave method. 
Is this intended behavior? Am I missing something?

Original issue reported on code.google.com by mann.mue...@gmail.com on 13 Jun 2014 at 12:44

GoogleCodeExporter commented 9 years ago
I should have read that last section again :)

In Objectify 4.1 this worked great, but after upgrading to 5.x, Objectify 
CHECKS if the key is set (which is not the case) and then throws an exception 
without calling the OnSave method. Is this intended behavior? Am I missing 
something?

Original comment by mann.mue...@gmail.com on 13 Jun 2014 at 12:46

GoogleCodeExporter commented 9 years ago
It is intended behavior. Updating @Id or @Parent is not supported in v5. Dev 
Docs say, "Caution: You can't update @Id or @Parent fields in a @OnSave 
callback"

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

Original comment by ashish.a...@gmail.com on 14 Jul 2014 at 4:04

GoogleCodeExporter commented 9 years ago
Okay, I did not see this. Would be cool though in cases where the entity key is 
aggregated from field-values. Any plans changing this some time?

Original comment by mann.mue...@gmail.com on 14 Jul 2014 at 4:10

GoogleCodeExporter commented 9 years ago

Original comment by lhori...@gmail.com on 3 Oct 2014 at 6:00