This has haunted me for the past two days, so I grabbed coffee and wasted an hour of my life, but I would like to show you how I earned:
In Global.scala put this:
override def onStart(app: Application) { SessionFactory.externalTransactionManagementAdapter = Some(() => { if(org.squeryl.Session.hasCurrentSession) { org.squeryl.Session.currentSessionOption.get } else { val s = new org.squeryl.Session(DB.getDataSource().getConnection(), new PostgreSqlAdapter){ override def cleanup = { super.cleanup unbindFromCurrentThread } } s.bindToCurrentThread s } }) }
And then you will need to clean up a bit so that your application does not distort (in the same global):
override def onRouteRequest(request: RequestHeader): Option[Handler] = { org.squeryl.Session.currentSessionOption.foreach(_.unbindFromCurrentThread) super.onRouteRequest(request) }
I will update this if I find any reservations, etc. Turning purification kindly http://lunajs.blogspot.ca/2011/06/squeryl-with-java-experiment.html
source share