google-code-export / morphia

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

java.lang.ClassCastException: org.bson.types.ObjectId cannot be cast to com.mongodb.DBObject #284

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago

java.lang.RuntimeException: java.lang.RuntimeException: 
java.lang.ClassCastException: org.bson.types.ObjectId cannot be cast to 
com.mongodb.DBObject
    at com.google.code.morphia.mapping.Mapper.fromDb(Mapper.java:487)
    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 com.google.code.morphia.query.QueryImpl.asList(QueryImpl.java:255)
    at transmachina.mongo.term.StopWord.getLowers(StopWord.java:70)
    at transmachina.mongo.term.StopWordTest.testLower(StopWordTest.java:16)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at com.intellij.junit3.JUnit3IdeaTestRunner.doRun(JUnit3IdeaTestRunner.java:139)
    at com.intellij.junit3.JUnit3IdeaTestRunner.startRunnerWithArgs(JUnit3IdeaTestRunner.java:52)
    at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:199)
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:62)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
Caused by: java.lang.RuntimeException: java.lang.ClassCastException: 
org.bson.types.ObjectId cannot be cast to com.mongodb.DBObject
    at com.google.code.morphia.mapping.EmbeddedMapper.fromDBObject(EmbeddedMapper.java:146)
    at com.google.code.morphia.mapping.Mapper.readMappedField(Mapper.java:507)
    at com.google.code.morphia.mapping.Mapper.fromDb(Mapper.java:484)
    ... 30 more
Caused by: java.lang.ClassCastException: org.bson.types.ObjectId cannot be cast 
to com.mongodb.DBObject
    at com.google.code.morphia.mapping.EmbeddedMapper.fromDBObject(EmbeddedMapper.java:136)
    ... 32 more

The class is:

@Entity
@Indexes({
        @Index(value = "language,text", unique = true),
        @Index(value = "language,textLc")
})
public class StopWord {

  @Id
  ObjectId id;

  @Indexed
  String text;

  @Indexed
  String textLc;

  @Reference
  Language language;

The query I made:

  public static List<String> getLowers(Language language) {
    Query<StopWord> query = Mongo.createQuery(StopWord.class)
            .field("language").equal(language)
            .retrievedFields(true, "textLc");
    List<StopWord> stopWords = query.asList();

Original issue reported on code.google.com by heaths.h...@gmail.com on 11 Jun 2011 at 4:52

GoogleCodeExporter commented 9 years ago
I have resolved this. I discovered that the ObjectId class imported was from 
OpenJPA (which is also in my classpath)

Original comment by heaths.h...@gmail.com on 11 Jun 2011 at 5:20

GoogleCodeExporter commented 9 years ago

Original comment by scotthernandez on 11 Jun 2011 at 11:08