Deleting entity with composite key fails using BasicDao

67 views
Skip to first unread message

Johan Haleby

unread,
Feb 24, 2012, 5:00:08 AM2/24/12
to Morphia
Hi,

I have a class that has a composite id, e.g.

public class Operator {

@Id
@Indexed(unique = true)
private final OperatorId operatorId;
..
}

The OperatorId looks like this:

public class OperatorId {
private final String x;
private final String y;

..
}

My repository implementation extends BasicDao<Operator, OperatorId>
but when I try to delete an entity either by using delete(operator) or
deleteById(operatorId) I get the following exception:

java.lang.IllegalArgumentException: can't serialize class
com.mycompany.OperatorId
at org.bson.BasicBSONEncoder._putObjectField(BasicBSONEncoder.java:
234)
at org.bson.BasicBSONEncoder.putObject(BasicBSONEncoder.java:121)
at org.bson.BasicBSONEncoder.putObject(BasicBSONEncoder.java:86)
at com.mongodb.DefaultDBEncoder.writeObject(DefaultDBEncoder.java:27)
at com.mongodb.OutMessage.putObject(OutMessage.java:142)
at com.mongodb.DBApiLayer$MyCollection.remove(DBApiLayer.java:289)
at com.mongodb.DBCollection.remove(DBCollection.java:239)
at com.google.code.morphia.DatastoreImpl.delete(DatastoreImpl.java:
121)
at com.google.code.morphia.DatastoreImpl.delete(DatastoreImpl.java:
136)
at com.google.code.morphia.DatastoreImpl.delete(DatastoreImpl.java:
140)
at com.google.code.morphia.dao.BasicDAO.deleteById(BasicDAO.java:150)

Saving and finding works just fine. What am I doing wrong?

Regards,
/Johan

Johan Haleby

unread,
Feb 24, 2012, 7:51:10 AM2/24/12
to Morphia
I suspect that this is a bug in Morphia. If I change
deleteById(operatorId) to

ds.findAndDelete(createQuery().field("_id") .equal(operatorId));

It works.

/Johan

On Feb 24, 11:00 am, Johan Haleby <johan.hal...@gmail.com> wrote:
> Hi,
>
> I have aclassthat has a composite id, e.g.

Johan Haleby

unread,
Feb 24, 2012, 8:41:51 AM2/24/12
to Morphia
I've verified that this is a bug, added issue 383 (http://
code.google.com/p/morphia/issues/detail?id=383) where I've attached a
patch.

/Johan

Scott Hernandez

unread,
Feb 24, 2012, 10:03:46 AM2/24/12
to mor...@googlegroups.com

I committed a different fix. Please let me know if there is a problem.

Reply all
Reply to author
Forward
0 new messages