Two Laptop Bag*
The moose likes Scala and the fly likes Scala Casbah - Cast Exception Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Languages » Scala
Bookmark "Scala Casbah - Cast Exception" Watch "Scala Casbah - Cast Exception" New topic
Author

Scala Casbah - Cast Exception

Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9345
    
    2

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?


SCJP 1.4, SCWCD 1.4 - Hints for you, Certified Scrum Master
Did a rm -R / to find out that I lost my entire Linux installation!
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9345
    
    2

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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Scala Casbah - Cast Exception
 
Similar Threads
Problem in Generic Override
How to populate the recordset for database connection using Javascript in ASP page ?
DATABASE OBJECT-- URGENT URGENT
ConnectionPool causing memory leak
Help with preventing duplicate elements in foreign key column