greenlaw110/play-morphia — Issue #54: Get Key<? extends Model> for an Entity
Author: ahmetalpbalkan
Created: 2011-11-26 12:13:53+00:00
State: open

When I want to create a new morphia Key type from these entities, what I do is

Key key = new Key(User.class, user._key());

It generates something like:

Key{kindClass=models.User, id=4ed0d5571a88f34ccf429e5d}

However after saving it and requesting from the database, it comes back as,

Key{kind=user, id=4ed0d5571a88f34ccf429e5d}

(note `kind` and `kindClass` types here.) Therefore, when I store a `Set>` field on an entity, I can't invoke `contains()` field of that entity because hashCodes are different because of `kind` and `kindClass` difference. It is because those keys are not generated with `kind`, instead they are generated by `kindClass`.

If Play-Morphia `Model` class can provide a method like `getMorphiaKey()` , it would be great. I'd like to implement it however could not find how to get a collection name of an entity in this plugin. Morphia `Key` type provides sufficient constructors.

Solutions are appreciated, thanks.