SalatDAO storing Maps

15 views
Skip to first unread message

Pat Ferrel

unread,
Dec 26, 2017, 10:27:29 AM12/26/17
to scala-salat
I see now that I have to supply an implementation for Map, so I changed Map the HashMap but still get an error that seems to indicate that SalatDAO only supports case classes?

11:07:31.884 ERROR LocalActorRefProvider(akka://harness-router) - guardian failed, shutting down system
salat.util.GraterGlitch: 

      GRATER GLITCH - unable to find or instantiate a grater using supplied path name

      REASON: Class scala.collection.immutable.HashMap is not an instance of CaseClass

      Context: 'global'
      Path from pickled Scala sig: 'scala.collection.immutable.HashMap'


       
at salat.Context$class.lookup(Context.scala:220)
at salat.global.package$$anon$1.lookup(global.scala:32)
at salat.package$.grater(package.scala:66)
at salat.dao.SalatDAO.<init>(SalatDAO.scala:54)

Does this mean Salat may support HashMaps but the DAO does not?

Noah Zucker

unread,
Dec 26, 2017, 10:36:29 AM12/26/17
to scala-salat
Correct, DAOs are intended to work with case classes. They don't work with HashMaps etc.

See:

https://github.com/salat/salat/wiki/SalatDAO

You can use Salat's grater to convert Map[String, Any] to/from JSON, but if you need to store in Mongo you may need to write additional integration code with Casbah, not using the Salat DAO-provided functions.

Pat Ferrel

unread,
Dec 26, 2017, 12:11:57 PM12/26/17
to scala-salat
Yeah I wrapped it in a case class that has nothing but a Map and it works now. BTW I read that wiki page and still do not see where it says DAOs are restricted to case classes. The only restrictions (elsewhere on the wiki) seems to allow Maps that have Strings as keys. That (I assume) applies to the lower level APIs not SalatDAO

Noah Zucker

unread,
Dec 26, 2017, 12:35:33 PM12/26/17
to scala-salat
SalatDAO is a convenience implementation that requires you provide a case class and an id of type Any.   It does in fact state that on the wiki under "getting started."

Salat doesn't come with a DAO implementation that gives you simple save / delete / etc. operations for Maps.

If you wanted to implement a DAO (superclass type of SalatDAO) that works with plan old Maps, you could certainly write your own DAO implementation (MapDAO I guess you would call it).
Reply all
Reply to author
Forward
0 new messages