There are no _id field in embedded elements.
>
> I want to delete one 'address' from the Person. The mongodb query
> works fine:
> db.Person.update({_id:"1"}, {$pull:{addresses:{_id:"22"}}}). So I need
> to remove an array element based on a value of its property (not its
> position in the array).
> How I can do same thing with Morphia API?
You can remove the array element by value using the update operations.
ops = datastore.createUpdateOperations(Person.class).removeAll("addresses",
new Address("Los Angeles"));
http://code.google.com/p/morphia/wiki/Updating#removeFirst/Last/All
> Thanks.
It is up to you if you want to assign a unique id for each array
element. It totally depends on the data and access you are using in
the embedded array (element).
You can even do this if you want to and then you won't need @PrePersist.
class Address {
private ObjectId id = new ObjectId();
private String city;
private String street;
}
>
> Did I get you idea?
Yep; I think so.
This issue is somewhat related:
http://code.google.com/p/morphia/issues/detail?id=179
> There could be some argument against that. Depending on what you are
> using @PrePersist for you may or may not want it run.
sound pretty unintuitive. would you care to give an example?
cu uwe