find exception in 106r1

19 views
Skip to first unread message

Pat Ferrel

unread,
Feb 13, 2014, 6:54:18 PM2/13/14
to mor...@googlegroups.com

I have a database which was created with Morphia. I run a job occasionally to add new data to the DB. Recently I reran the code, with a few bugs fixed. Since the last time I ran the job I’ve upgraded to the tagged version of 106 and upgraded MongoDB to 2.4.9. Everything seems to be fine with all this, the DB drives a site in RoR and all the sites and scripts seem to work fine. 

However when I run my update job I get an error on every execution of this line from the DAO:

    public T findOne(final String key, final Object value) {

         return ds.find(this.collectionName, entityClazz, key, value, 0, 0, true).get();

    }

When I call the above DAO function like this:

    Video v = vd.findOne("item_id", videoId);//Mongo is set for no exception if not found, only for real errors

As I said, this exact line of code has worked with previous version of Mongo (earlier 2.0-something) and previous Morphia (earlier 106 snapshot). The query works in the Mongo shell: db.videos.find({'item_id':'some_id'}) with the same id.

BTW has anything changed with the way the className field is used? I'd rather disable its storage since I refactor the packaging occasionally. 


14/02/13 15:17:48 INFO mapred.LocalJobRunner: file:/Users/pat/big-data/mini-guide/crawl/5-20140213T121656/media/part-00000:0+17378

java.lang.RuntimeException: java.lang.ClassCastException: java.lang.String cannot be cast to com.mongodb.DBObject

at org.mongodb.morphia.mapping.EmbeddedMapper.fromDBObject(EmbeddedMapper.java:172)

at org.mongodb.morphia.mapping.Mapper.readMappedField(Mapper.java:606)

at org.mongodb.morphia.mapping.Mapper.fromDb(Mapper.java:581)

at org.mongodb.morphia.mapping.Mapper.fromDBObject(Mapper.java:296)

at org.mongodb.morphia.query.MorphiaIterator.convertItem(MorphiaIterator.java:78)

at org.mongodb.morphia.query.MorphiaIterator.processItem(MorphiaIterator.java:65)

at org.mongodb.morphia.query.MorphiaIterator.next(MorphiaIterator.java:60)

at org.mongodb.morphia.query.QueryImpl.get(QueryImpl.java:403)

at com.finderbots.recommenders.hadoop.mongo.BasicNamedDAO.findOne(BasicNamedDAO.java:246)

at com.finderbots.guide.ingest.IngestMinedVideosAndPrefsWorkflow$InsertInMongoFunction.operate(IngestMinedVideosAndPrefsWorkflow.java:291)

at cascading.flow.stream.FunctionEachStage.receive(FunctionEachStage.java:99)

at cascading.flow.stream.FunctionEachStage.receive(FunctionEachStage.java:39)

at cascading.flow.stream.SourceStage.map(SourceStage.java:102)

at cascading.flow.stream.SourceStage.run(SourceStage.java:58)

at cascading.flow.hadoop.FlowMapper.run(FlowMapper.java:127)

at org.apache.hadoop.mapred.MapTask.runOldMapper(MapTask.java:436)

at org.apache.hadoop.mapred.MapTask.run(MapTask.java:372)

at org.apache.hadoop.mapred.LocalJobRunner$Job.run(LocalJobRunner.java:212)

Caused by: java.lang.ClassCastException: java.lang.String cannot be cast to com.mongodb.DBObject

at org.mongodb.morphia.mapping.EmbeddedMapper.readCollection(EmbeddedMapper.java:203)

at org.mongodb.morphia.mapping.EmbeddedMapper.fromDBObject(EmbeddedMapper.java:144)

... 17 more


Pat Ferrel

unread,
Feb 14, 2014, 11:16:18 AM2/14/14
to mor...@googlegroups.com
The part of me that works while I sleep came up with the answer:

Problem 1) I had changed a field from String to ArrayList<String> AND the field has been initialized with empty Strings
Solution) $unset all of the blank fields like this: db.videos.update({  'sources': { '$exists': true } },{ '$unset': { 'sources' : true  } },false, true) This removes the fields on all docs so the new 'schema' will find and initialize the object correctly and when written will add the new sources: ArrayList<String>.

Problem 2) mixed className fields from refactoring into new package structure.
Solution) db.videos.update({  'className': { '$exists': true } },{ '$unset': { 'className' : true  } },false, true) to remove all className fields--careful using classNames, they freeze your package structure. Then I also added the following to my serializable class: @Entity(noClassnameStored=true)

All works fine now.

Note to self: Schemaless does not mean changes can be made with impunity. Consider writing migrations for every class structure change.


Justin Lee

unread,
Feb 18, 2014, 9:32:34 AM2/18/14
to mor...@googlegroups.com
Oh, good.  I'm glad to see you got it resolved.  I apologize for not getting back to you sooner.  I had taken a few days off and just got back in to the office.


--
You received this message because you are subscribed to the Google Groups "Morphia" group.
To unsubscribe from this group and stop receiving emails from it, send an email to morphia+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply all
Reply to author
Forward
0 new messages