A Grails 2.3.4
application is connecting to an Oracle database using the following domain class:
class Person {
String name
static mapping = {
id column: "PERSON_ID", generator: "sequence", params: [sequence: 'person_seq']
}
}
The PersonController
makes a call to a method in PersonService
and it makes a call to UtilService
. The method in UtilService
being called has some logic based on wether this Person
object is new:
if (personInstance.id == null) { ... }
What I have found is that the id
property of personInstance
(which is passed through the method calls described above) is assigned when the UtilService
is called.
The controller action calling PersonService
is @Transactional
, and the services do not have any transaction configuration.
So, a couple of questions:
- When is
id
value assigned by GORM (I assumed at insert but that seems wrong)? - Is there a better way of checking if the object is new (
isAttached()
returnstrue
so that's not good for me)?
EDIT: save()
has not been called on the personInstance
when UtilService
does the id
check.