jkuehn / gorm-mongodb

Grails GORM implementation for the MongoDB document oriented database
http://www.grails.org/plugin/mongodb-morphia
Apache License 2.0
21 stars 14 forks source link

Getting exception "com.mongodb.BasicDBObject cannot be cast to com.mongodb.DBRef" #6

Closed countvajhula closed 13 years ago

countvajhula commented 13 years ago

Hi, I have a mongo domain class called MyClass, which contains a non-Id member variable called "Long myMember". When I call the GORM method MyClass.findByMyMember(someValue), I get the java.lang.ClassCastException noted in the title. If I change findByMyMember to findAllByMyMember(someValue), it doesn't complain initially and simply returns an object of type com.google.code.morphia.query.MorphiaIterator@284eb041. But, if I now attempt to access it.next(), it once again gives the same exception, for which the stacktrace is below:

java.lang.ClassCastException: com.mongodb.BasicDBObject cannot be cast to com.mongodb.DBRef at com.google.code.morphia.mapping.ReferenceMapper.readCollection(ReferenceMapper.java:224) at com.google.code.morphia.mapping.ReferenceMapper.fromDBObject(ReferenceMapper.java:143) at com.google.code.morphia.mapping.Mapper.readMappedField(Mapper.java:505) at com.google.code.morphia.mapping.Mapper.fromDb(Mapper.java:484) at com.google.code.morphia.mapping.Mapper.fromDBObject(Mapper.java:267) at com.google.code.morphia.query.MorphiaIterator.convertItem(MorphiaIterator.java:66) at com.google.code.morphia.query.MorphiaIterator.processItem(MorphiaIterator.java:53) at com.google.code.morphia.query.MorphiaIterator.next(MorphiaIterator.java:48) at java_util_Iterator$next.call(Unknown Source)

Btw I'm not able to join the Grails User mailing lists as access to new users has been broken for at least a few weeks now, and reporting that issue on IRC and Twitter hasn't helped. Otherwise I would've asked the question there first before opening an issue. Thanks for any help! Let me know if you need more information,

-Sid

jkuehn commented 13 years ago

Did you resolve this issue? Can you provide your domain class and the line where you call MyClass.findByMyMember? Also try this query on an empty database. I once had messed up references in the database that caused the same error

countvajhula commented 13 years ago

I reported this on the morphia mailing list a little while back, that thread is here: http://groups.google.com/group/morphia/browse_thread/thread/72dd9369edd11e89

I didn't really get at the root cause of this but I'm not currently seeing this exception after a change I made (which I noted in that thread on morphia). If I see this exception again I'll try to create a test application that reproduces it. Thanks, and great work on the plugin!