google-code-export / morphia

Automatically exported from code.google.com/p/morphia
1 stars 0 forks source link

delete not happening #272

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Kenny,
Here is the description of the problem I uncovered with Morphia. Let us say 
that an entity is defined with the Morphia @Id annotation placed on a String 
field (say, String id). Then, adding the entity, and querying for it, all works 
fine. The problem comes when we use the Morphia delete(T entity) method – it 
just does not delete the object. 

@Entity(value = "collection", noClassnameStored=true)
public class Entity
{
…..
    @Id
    private String id;
}

            WriteResult wr = datastore.delete(entity);

does not delete the entity. However, the following call does do the delete:

            if(id instanceof String) id = new ObjectId((String)id);
            WriteResult wr = datastore.delete(entity.getClass(), id);

Original issue reported on code.google.com by kgorman%...@gtempaccount.com on 3 May 2011 at 10:53

GoogleCodeExporter commented 9 years ago
Yep, you have a type mismatch at the database since the id as a string is not 
the same as the id as an ObjectId().

There is no way to to fix this in morphia except to disallow inserts/saves if 
the id field doesn't exist; even that won't fix it if you have data already 
that meats this criteria.

Original comment by scotthernandez on 3 May 2011 at 10:58