list and create CRUDify pages are accessible under
localhost:8080/root/users/list &
localhost:8080/root/users/create as expected, however
delete, edit & view pages all return the following exception:
Exception occured while processing /root/users/view/1
Message: java.lang.RuntimeException: no session is bound to current
thread, a session must be created via Session.create
and bound to the thread via 'work' or 'bindToCurrentThread'
I understand, all calls to squeryl need to reside in a transaction
block. This is why I used the following code in my Boot.scala:
S.addAround(new LoanWrapper{override def apply[T](f: => T): T =
{inTransaction{f}}})
For some reason this works only with list and create pages.
Other pages throw exception.
Please, does anybody know why is it so or how to fix it?
I will gladly provide any further details needed.
--
Lift, the simply functional web framework: http://liftweb.net
Code: http://github.com/lift
Discussion: http://groups.google.com/group/liftweb
Stuck? Help us help you: https://www.assembla.com/wiki/show/liftweb/Posting_example_code
It would be great if someone could explain why this is needed (well I
guess the call is done outside of a session ;) )
best regards
Peter Petersson
On 2011-12-05 15:41, Olek Swirski wrote:
> I'm trying to use net.liftweb.squerylrecord.CRUDify.
> I use lift 2.4-M5, jetty 8 + H2 in-memory database.
> For testing I set up a simple User entity. In User meta
> object I changed the default location for CRUDify pages:
> override lazy val Prefix = List("root","users").
>
> list and create CRUDify pages are accessible under
> localhost:8080/root/users/list&
> localhost:8080/root/users/create as expected, however
> delete, edit& view pages all return the following exception:
> This may be a workaround however I don't know if this is the right approach but in addition to the loanwrapper function I have found the need to surround some db calls with net.liftweb.squerylrecord.RecordTypeMode.transaction to avoid the same exception.
> example:
> def prepareAllCountryCodes(): List[CountryCodes] = transaction {
> List(
> CountryCodes.createRecord.a2("AF").a3("AFG").num(4).country("AFGHANISTAN"),
> CountryCodes.createRecord.a2("AL").a3("ALB").num(8).country("ALBANIA"),
> :
>
> It would be great if someone could explain why this is needed (well I guess the call is done outside of a session ;) )
Basically, all that the loanWrapper does is that it wraps the entire request within a transaction. So as far as you are within the scope of a request, you should be fine. However, if you are outside of request scope, you need to wrap all database calls with a transaction{} or inTransaction{} block. A good example is a Boot.scala, if you do something with a database in Boot (eg. I do some caching there in some applications) it needs to go inside transaction{} block, because there is no request, thus loanWrapper doesn't take place.
Does that answer your question?
>
> best regards
> Peter Petersson
>
> On 2011-12-05 15:41, Olek Swirski wrote:
>> I'm trying to use net.liftweb.squerylrecord.CRUDify.
>> I use lift 2.4-M5, jetty 8 + H2 in-memory database.
>> For testing I set up a simple User entity. In User meta
>> object I changed the default location for CRUDify pages:
>> override lazy val Prefix = List("root","users").
>>
>> list and create CRUDify pages are accessible under
>> localhost:8080/root/users/list&
>> localhost:8080/root/users/create as expected, however
>> delete, edit& view pages all return the following exception:
>>
>> Exception occured while processing /root/users/view/1
>> Message: java.lang.RuntimeException: no session is bound to current
>> thread, a session must be created via Session.create
>> and bound to the thread via 'work' or 'bindToCurrentThread'
>>
>> I understand, all calls to squeryl need to reside in a transaction
>> block. This is why I used the following code in my Boot.scala:
>> S.addAround(new LoanWrapper{override def apply[T](f: => T): T =
>> {inTransaction{f}}})
>> For some reason this works only with list and create pages.
>> Other pages throw exception.
>>
>> Please, does anybody know why is it so or how to fix it?
>> I will gladly provide any further details needed.
>>
>
On Dec 6, 7:05 pm, Olek Swirski <olekswir...@gmail.com> wrote:
> ok, I have put a stripped down version of my problematic lift-app on github
> git://github.com/oolekk/dist_test.git
> there is only index.html in webapp dir and from there list and create pages
> generated by CRUDify are accesible. when I go to the list page I can see 2
> rows initialized within Boot.scala, there are also links to edit, delete,
> view pages, but these throw Exception. So the question is, what to do for
> it to work as expected? It's quite possible I made some basic mistake so
> please forgive if this is the case :) Exception type makes me think, that
> for some reason transaction-wrapping doesn't work for delete,edit & view
> pages. But maybe the problem is with db connection - however some initial
> data is loaded without problem into db in Boot.scala. in-memory DB can be
> monitored underhttp://localhost:8080/console/after starting this app in
> sbt (container:start). Another possible reason is maybe due to the fact
> that I try to use connection pooler - BoneCP, but I guess it's needed to
> get reasonable performance. Any help will be greately appreciated :-)
>
> On 6 December 2011 05:59, Olek Swirski <olekswir...@gmail.com> wrote:
>
>
>
>
>
>
>
> > ok, I will put example code on github. sorry for the duplicated topic - I
> > submitted the other one much earlier and I thought that maybe it got
> > moderated as it was too long or something, so I shortened it and sent again.
>
> > On 5 December 2011 17:48, Peter Petersson <petersson.pe...@gmail.com>wrote:
>
> >> On 2011-12-05 17:41, Ján Raska wrote:
>
> >>> On Dec 5, 2011, at 17:27 , Peter Petersson wrote:
>
> >>> This may be a workaround however I don't know if this is the right
> >>>> approach but in addition to the loanwrapper function I have found the need
> >>>> to surround some db calls with net.liftweb.squerylrecord.**RecordTypeMode.transaction
> >>>> to avoid the same exception.
> >>>> example:
> >>>> def prepareAllCountryCodes(): List[CountryCodes] = transaction {
> >>>> List(
> >>>> CountryCodes.createRecord.a2("**AF").a3("AFG").num(4).country(**
> >>>> "AFGHANISTAN"),
> >>>> CountryCodes.createRecord.a2("**AL").a3("ALB").num(8).country(**
> >>>> "ALBANIA"),
> >>>> :
>
> >>>> It would be great if someone could explain why this is needed (well I
> >>>> guess the call is done outside of a session ;) )
>
> >>> Basically, all that the loanWrapper does is that it wraps the entire
> >>> request within a transaction. So as far as you are within the scope of a
> >>> request, you should be fine. However, if you are outside of request scope,
> >>> you need to wrap all database calls with a transaction{} or inTransaction{}
> >>> block. A good example is a Boot.scala, if you do something with a database
> >>> in Boot (eg. I do some caching there in some applications) it needs to go
> >>> inside transaction{} block, because there is no request, thus loanWrapper
> >>> doesn't take place.
>
> >>> Does that answer your question?
>
> >> yes that clearly explains why I needed it wile doing db init stuff.
> >> thanks
>
> >>> best regards
> >>>> Peter Petersson
>
> >>>> On 2011-12-05 15:41, Olek Swirski wrote:
>
> >>>>> I'm trying to use net.liftweb.squerylrecord.**CRUDify.
> >>>>> I use lift 2.4-M5, jetty 8 + H2 in-memory database.
> >>>>> For testing I set up a simple User entity. In User meta
> >>>>> object I changed the default location for CRUDify pages:
> >>>>> override lazy val Prefix = List("root","users").
>
> >>>>> list and create CRUDify pages are accessible under
> >>>>> localhost:8080/root/users/**list&
> >>>>> localhost:8080/root/users/**create as expected, however
> >>>>> delete, edit& view pages all return the following exception:
>
> >>>>> Exception occured while processing /root/users/view/1
> >>>>> Message: java.lang.RuntimeException: no session is bound to current
> >>>>> thread, a session must be created via Session.create
> >>>>> and bound to the thread via 'work' or 'bindToCurrentThread'
>
> >>>>> I understand, all calls to squeryl need to reside in a transaction
> >>>>> block. This is why I used the following code in my Boot.scala:
> >>>>> S.addAround(new LoanWrapper{override def apply[T](f: => T): T =
> >>>>> {inTransaction{f}}})
> >>>>> For some reason this works only with list and create pages.
> >>>>> Other pages throw exception.
>
> >>>>> Please, does anybody know why is it so or how to fix it?
> >>>>> I will gladly provide any further details needed.
>
> >>>>> --
> >>>> Lift, the simply functional web framework:http://liftweb.net
> >>>> Code:http://github.com/lift
> >>>> Discussion:http://groups.google.com/**group/liftweb<http://groups.google.com/group/liftweb>
> >>>> Stuck? Help us help you:https://www.assembla.com/wiki/**
> >>>> show/liftweb/Posting_example_**code<https://www.assembla.com/wiki/show/liftweb/Posting_example_code>
>
> >> --
> >> Lift, the simply functional web framework:http://liftweb.net
> >> Code:http://github.com/lift
> >> Discussion:http://groups.google.com/**group/liftweb<http://groups.google.com/group/liftweb>
> >> Stuck? Help us help you:https://www.assembla.com/wiki/**
> >> show/liftweb/Posting_example_**code<https://www.assembla.com/wiki/show/liftweb/Posting_example_code>
On 2011-12-07 08:10, Olek Swirski wrote:
> I checked if the same thing happens when I use MySQL instead of H2 db,
> and noticed that with MySQL even the list CRUDify page is gone. I now
> think, that the source of my problem is probably in BoneCP connection
> pool configuration and not in CRUDify or squeryl-record.
>
> On Dec 6, 7:05 pm, Olek Swirski<olekswir...@gmail.com> wrote:
>> ok, I have put a stripped down version of my problematic lift-app on github
>> git://github.com/oolekk/dist_test.git
>> there is only index.html in webapp dir and from there list and create pages
>> generated by CRUDify are accesible. when I go to the list page I can see 2
>> rows initialized within Boot.scala, there are also links to edit, delete,
>> view pages, but these throw Exception. So the question is, what to do for
>> it to work as expected? It's quite possible I made some basic mistake so
>> please forgive if this is the case :) Exception type makes me think, that
>> for some reason transaction-wrapping doesn't work for delete,edit& view
>> pages. But maybe the problem is with db connection - however some initial
>> data is loaded without problem into db in Boot.scala. in-memory DB can be
>> monitored underhttp://localhost:8080/console/after starting this app in
>> sbt (container:start). Another possible reason is maybe due to the fact
>> that I try to use connection pooler - BoneCP, but I guess it's needed to
>> get reasonable performance. Any help will be greately appreciated :-)
>>
>> On 6 December 2011 05:59, Olek Swirski<olekswir...@gmail.com> wrote:
>>
>>
>>
>>
>>
>>
>>
>>> ok, I will put example code on github. sorry for the duplicated topic - I
>>> submitted the other one much earlier and I thought that maybe it got
>>> moderated as it was too long or something, so I shortened it and sent again.
>>> On 5 December 2011 17:48, Peter Petersson<petersson.pe...@gmail.com>wrote:
Discussion: http://groups.google.com/group/liftweb
Stuck? Help us help you: https://www.assembla.com/wiki/show/liftweb/Posting_example_code
12:16:29.865 [qtp1560165012-41738 - /user/view/1] INFO bootstrap.liftweb.Boot - LOANWRAPPER INTRANSACTION Full(Req(List(), Map(), ParsePath(List(user, view, 1),,true,false), , GetRequest, Empty))
12:16:29.943 [qtp1560165012-41738 - /user/view/1] ERROR net.liftweb.http.LiftRules - Exception being returned to browser when processing /user/view/1: Message: java.lang.RuntimeException: no session is bound to current thread, a session must be created via Session.create
and bound to the thread via 'work' or 'bindToCurrentThread'
but yes there are some rewrites going on.
I have stripped down your example as much as I can, removing the pool,
session factory, servlet filtering and messing around with the crudify
stuff, but I am afraid I am a novice when it comes to the CRUDify stuff
so your question stands why dose clicking on the delete, view, edit
links on the "crudified"-page result in the "no session is bound to
current thread" error when create is working great.
The only thing that comes to my mind when it come to the crudify stuff
is that crudify create of a new user do no involve lookup by a Id field
wiles all of delete, view and edit needs it, so for instance how dose
the crudify stuff translate the path "/user/view/1" into a view of user
data for id=1 ?
It has been a fun ride but I am afraid to no or little avail for you but
the in-memory-db/console stuff is definitely cool so thanks for the
example.
Hopefully someone else will jump in and take a stab at this.
best regards
Peter Petersson
Discussion: http://groups.google.com/group/liftweb
Stuck? Help us help you: https://www.assembla.com/wiki/show/liftweb/Posting_example_code