when i call this code, i get an `IllegalStateExcep...
# exposed
j
when i call this code, i get an
IllegalStateException: No transaction in context
. anyone know what i’m doing wrong here?
Copy code
val breakdownDimensions = transaction {
                Dimension.find {
                    Dimensions.id inList breakdownIds
                }
            }

            for (dimension in breakdownDimensions) {
                println(dimension.id)
            }
e
did you wrap this into
transaction { }
?
j
there’s a transaction in the code i posted
i’m not entirely clear on what the issue was, but wrapping all of the code that uses my database types in a transaction did fix my problem
e
yeah in order to be able to use them, you must be inside a transaction
j
@John Pena I believe
Dimension.find
returns a
SizedIterable
which hasn't actually queried yet. The reason is that you could be asking for count, or existence, something that doesn't require the query to be completed in full. The query is actually occurring when you access the iterator using
dimension in breakdownDimensions
. The fix would be to use:
Copy code
Dimension.find { Dimensions.id inList breakdownIds }.toList()
1
j
helpful, thanks @Joel!
👍 1