What database type are you using?

I would use query.last() (not query.next())
That positions you on the query you just executed.