2.9.1 embedded case classes, test failures

147 views
Skip to first unread message

Hugh

unread,
May 13, 2012, 9:35:13 PM5/13/12
to scala-salat
Hi,

I've been playing with Salat over the weekend and have had trouble
getting even very basic nested case classes to work.

The problem seems to be that all nested classes are written to the
DBObject as-is rather than being evaluated themselves, which means
that when you write them down to mongo, they get serialized as a
BasicDBList. When you then try to load it back from the datastore, you
get errors because the constructors don't match (nested type vs
BasicDBList). I've put up a gist which shows the problem:

https://gist.github.com/2691137

Furthermore, I checked out the latest source from git, and running the
tests against scala 2.9.1 rather than 2.8.1 caused a whole load of
errors of the form:

MatchError: NullaryMethodType(TypeRefType....<snip> Grater.scala:194

If I use the latest snapshot of salat rather than the current maven
repo version on the gist above, I get similar errors to the above,
instead of the constructor-mismatch issue.

Are these related? Is this a configuration problem, or are these known
issues? Is there any way around them to make Salat usable on 2.9.1?
I'd be happy to help out where I can to get it working if changes are
needed.

Best,
Hugh

rktoomey

unread,
May 13, 2012, 10:48:49 PM5/13/12
to scala-salat
Hi Hugh,

Salat explicitly does not support nested classes:
https://github.com/novus/salat/wiki/SupportedTypes

There are a few threads in the mailing list discussing why, but it all
comes down to the constructor requiring a reference to an instance of
the outer class

Now, the reason why you are having trouble running trunk against 2.9.1
is that master is specific to 2.8.1. Did you just manually edit the
sbt build file or something? Unfortunately, pickled Scala signatures
changed slightly - the nullary thing you mentioned - between 2.8.1 and
2.9.x. The 2.9.x stuff is in a branch still, although I will fold
that into master with the imminent release of 0.0.8.

To run the tests on 2.9.1, go to your checkout of salat and check out
the 2.9.1 branch:
salat $ git checkout 0.0.8_2.9.0-1

All the tests in 2.9.1 are passing for me, and in the Travis CI build:
http://travis-ci.org/#!/novus/salat

Sorry about the nested case class thing. It's easy to identify the
condition but I have not yet devised a way to supply the silly
instance of the outer class that the inner class constructor requires.

Best,
Rose

rose katherine toomey

unread,
May 13, 2012, 11:04:37 PM5/13/12
to scala-salat
OK, sorry, looked at your gist. You actually have a different
problem: namely, you need to declare your classes in a package. That
will sort everything.

Here's a gist where I moved your model classes into package hugh.model
and then took it for a spin in sbt console - everything works fine,
try it out in your checkout of salat or in your own project:
https://gist.github.com/2691508

Sorry about that - thought you meant embedded as in wanting to persist
a case class embedded in some outer structure.

Best,
Rose

Hugh

unread,
May 14, 2012, 12:56:23 PM5/14/12
to scala-salat
Hi Rose,

Just tried that and it worked a charm, thanks. Did I miss that in the
documentation somewhere?

Guilty as charged on running the tests - I simply changed the version
in the SBT build file on master.

Best,
Hugh

On May 13, 11:04 pm, rose katherine toomey <rktoo...@gmail.com> wrote:

> OK, sorry, looked at your gist.   You actually have a different
> problem: namely, you need to declare your classes in a package.  That
> will sort everything.
>
> Here's a gist where I moved your model classes into package hugh.model
> and then took it for a spin in sbt console - everything works fine,
> try it out in your checkout of salat or in your own project:https://gist.github.com/2691508
>
> Sorry about that - thought you meant embedded as in wanting to persist
> a case class embedded in some outer structure.
>
> Best,
> Rose
>
Reply all
Reply to author
Forward
0 new messages