ResultSet is closed outside of transaction

229 views
Skip to first unread message

des.m...@gmail.com

unread,
Nov 21, 2014, 5:28:12 AM11/21/14
to squ...@googlegroups.com
Hi

I am having a problem with the following code:

        val rows = transaction {
            myTable.where(t => t.x === 2).toSeq
        }
       
        rows.foreach(println(_))

Once I try to print out the rows I get the exception below. But if I modify the transaction thus:


transaction {
  val rows = myTable.where(t => t.x === 2).toSeq
  rows.size
  rows
}

It works fine but this is hardly the right solution. What might I be doing wrong? I am using version 0.9.6-RC2 with Postgresql 9.3 JDBC 4

Thanks
Des

Exception in thread "main" org.postgresql.util.PSQLException: This ResultSet is closed.
    at org.postgresql.jdbc2.AbstractJdbc2ResultSet.checkClosed(AbstractJdbc2ResultSet.java:2839)
    at org.postgresql.jdbc2.AbstractJdbc2ResultSet.next(AbstractJdbc2ResultSet.java:1889)
    at org.apache.commons.dbcp2.DelegatingResultSet.next(DelegatingResultSet.java:191)
    at org.apache.commons.dbcp2.DelegatingResultSet.next(DelegatingResultSet.java:191)
    at org.squeryl.dsl.AbstractQuery$$anon$1._next(AbstractQuery.scala:182)
    at org.squeryl.dsl.AbstractQuery$$anon$1.hasNext(AbstractQuery.scala:199)
    at org.squeryl.internals.IteratorConcatenation._hasNext(Utils.scala:120)
    at org.squeryl.internals.IteratorConcatenation.hasNext(Utils.scala:123)
    at scala.collection.Iterator$class.toStream(Iterator.scala:1143)
    at org.squeryl.internals.IteratorConcatenation.toStream(Utils.scala:109)
    at scala.collection.Iterator$$anonfun$toStream$1.apply(Iterator.scala:1143)
    at scala.collection.Iterator$$anonfun$toStream$1.apply(Iterator.scala:1143)
    at scala.collection.immutable.Stream$Cons.tail(Stream.scala:1085)
    at scala.collection.immutable.Stream$Cons.tail(Stream.scala:1077)
    at scala.collection.immutable.Stream.foreach(Stream.scala:548)

Maxime Lévesque

unread,
Nov 21, 2014, 8:26:36 AM11/21/14
to Squeryl

toSeq lazily converts the Iterable (Query) to a Seq, so the consumption of the resultset doesn't start
until the Seq is iterated upon. A non lazy conversion like toList will not have this problem.
I agree that this isn't very intuitive.



--
You received this message because you are subscribed to the Google Groups "Squeryl" group.
To unsubscribe from this group and stop receiving emails from it, send an email to squeryl+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

des.m...@gmail.com

unread,
Nov 21, 2014, 10:42:08 AM11/21/14
to squ...@googlegroups.com
So withing my transaction block I guess I could to something like:

rows.toList.toSeq

Are there perhaps performance issues here with the result set getting traversed twice when only one iteration is required?

David Whittaker

unread,
Nov 21, 2014, 12:01:34 PM11/21/14
to squ...@googlegroups.com
There is no need for the toSeq.  List already implements the Seq trait.

--
Reply all
Reply to author
Forward
0 new messages