When using the save() without flush: true, the instance is in the hibernate session, not in the database. So is there anyway that we can search the instances in the session?
Update: I have a queue of objects and use them to either create or update another object Number:
def inst = getNextOneFromQueue()
Number num = Number.findWhere(a:inst.a, b:ins.b)
If (num == null){
num = new Number()
}
num.a = inst.a
num.b = inst.b
num.save()
ins.delete(flush:true)
So the problem is i have to set flush:true in the delete or save method for each object I have in the queue. Otherwise if object num is created but not flushed to the database, there might be a possibility that an update on num could not find it in the database and create a new one (which is a duplicate).
But flushing every time is really inefficient. I'm thinking about not setting flush:true and search in the hibernate session to do the update. Is this possible? Any Suggestions? Work around?
I did a test. Create a new Number object num, save it without flush and then search for it right away:
Number num = new Number()
num.a = 234
num.save()
def temp = Number.findWhere(a:234) //Number.findByA(234)
temp is NULL. Apparently findWhere/findByA is search in the database.
Domain.get(id)(ifidis known) orDomain.findByAbc('Test')(if propertyabcon Domain is known)? What have you tried yet? - dmahapatro