It looks a little like the RequestVar has had its lifecycle closing hook called by the time you call getSubscriptions Try touch/get the subscriptions before you pass them into the bind.
cheers Oliver On Tue, Sep 9, 2008 at 7:31 AM, Kris Nuttycombe <[EMAIL PROTECTED]>wrote: > > I've been following the advancement of the JPA/Lift tutorial with > great interest, and have managed to get my app working, but I'm now > struggling with a problem that occurs whenever I try to retrieve a > collection that is mapped as a lazy association: > > Exception occured while processing /orders/list > > Message: org.hibernate.LazyInitializationException: failed to lazily > initialize a collection of role: > com.gaiam.gcsi.entities.subscription.Order.subscriptions, no session > or session was closed > > > org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersistentCollection.java:358) > > > org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationExceptionIfNotConnected(AbstractPersistentCollection.java:350) > > > org.hibernate.collection.AbstractPersistentCollection.readSize(AbstractPersistentCollection.java:97) > org.hibernate.collection.PersistentBag.size(PersistentBag.java:225) > com.gaiam.gcsi.snippet.Orders$$anonfun$list$1.apply(Orders.scala:21) > com.gaiam.gcsi.snippet.Orders$$anonfun$list$1.apply(Orders.scala:18) > scala.Seq$class.flatMap(Seq.scala:267) > com.gaiam.gcsi.model.EM$$anon$1.flatMap(EM.scala:11) > com.gaiam.gcsi.snippet.Orders.list(Orders.scala:18) > sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) > ... > > I took the simplest-possible route of encapsulating the EntityManager > in a RequestVar per Derek's suggestion as such: > > object EM { > def entityManager() = (new > > InitialContext()).lookup("java:comp/env/persistence/em").asInstanceOf[EntityManager] > } > > class Orders { > object em extends RequestVar(entityManager()) > > def list(xhtml: NodeSeq) : NodeSeq = { > val orders = em.createQuery("from > Order").getResultList().asInstanceOf[java.util.List[Order]] > orders.flatMap(order => > bind("order", xhtml, > "id" --> Text(order.getId().toString), > "count" --> Text(order.getSubscriptions().size().toString))) > } > } > > The issue appears to be that the transaction that the the query ran in > is no longer active by the time of the call to > order.getSubscriptions(). Has anyone else been using JTA and > encountered this? I'm running the latest stable Glassfish (2.1 UR2) > and using Hibernate for the persistence layer. > > Thanks, > > Kris > > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Lift" group. To post to this group, send email to liftweb@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/liftweb?hl=en -~----------~----~----~----~------~----~------~--~---