Hi @all!
I am a scala noob doing my first steps with scalatra.
I would like to use scalatra as a backend for my webapp.
My first goal was to generate new players (hardcoded), persist them, read them from database and return them as JSON.
So first I followed the scalatra JSON guide to change the default output to JSON.
Then I followed the scalatra SQUERYL guide to get a minimum of persistence working.
Now I am stuck at the point where the selection result should be returned:
get("/") {
inTransaction {
List(from(MassTournamentSchema.players)(select(_)))
}
}
I get the following error:
"No session is bound to current thread, a session must be created via
Session.create and bound to the thread via 'work' or
'bindToCurrentThread' Usually this error occurs when a statement is
executed outside of a transaction/inTrasaction block ".
If I iterate over the result inside the "inTransaction{...}" block, everything is okay.
Reading http://squeryl.org/selects.html
says: "[...] the query is sent to the database only when starting
iteration, or in other words, when Iterable.iterator is called. [...]".
Does anyone have an
idea?
Is my setup for auto JSON generation not working if I try to select from database and return directly?
THX!