Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to retrieve the latest created db entry?

Tags:

grails

groovy

I have the following class and need to manually increment the nextId field.

class SomeIdClass {

Family family
Integer nextId = 0
long timeCreated = new Date().time }

So far I've been trying to retrieve and the latest db entry to increment it and I'm just not having any luck with that. Or am I just going about it in a totally wrong manner?

Thaks

ps: this is what I tried but get a list of Package.SomeId objects

 def si = SomeId.executeQuery(" from SomeId where nextId =  (select max( nextId ) from SomeId) ")
like image 820
vector Avatar asked Feb 22 '11 21:02

vector


1 Answers

My two cents for return the last row in Grails:

DomainClass.find("from DomainClass order by id desc")
like image 120
Arturo Herrero Avatar answered Sep 20 '22 15:09

Arturo Herrero