Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Scala Casbah - Cast Exception

 
Joe Harry
Ranch Hand
Posts: 10087
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm using the Casbah library to fetch results from a MongoDB database. I'm noticing a strange error when I wanted to transform from the DBObject types to my case classes.

This is my collection in the database:



I want the array of answers to box to my Answer case class which is represented as a List in my Question case class as List[Answer]. The method below would do that for me:



The result of the method above when called like:



is the following RuntimeException:



Why is this? I'm explicitly passing Answer to the toList method call. Why should it fail?
 
Joe Harry
Ranch Hand
Posts: 10087
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I got rid of this error by using Salat DAO framework for Scala and MongoDBI got rid of this error by using Salat DAO library for Scala and MongoDB. Salat library has very good wrappers around Casbah that eliminates the need to converting between object types. It is all done behind the scenes.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic