To force grails to use strings for identifiers, simply declare the property String id. To populate it with a custom UUID, I would use the sleep id generator instead of beforeInsert. Create a class that extends org.hibernate.id.IdentifierGenerator, and then add an id identifier mapping to your domain class as follows:
class MyIdGenerator extends IdentifierGenerator {
Serializable generate(SessionImplementor session, Object object) {
return MyUUID.generate()
}
}
class MyDomain {
String id
static mapping = {
id generator:"my.package.MyIdGenerator", column:"id", unique:"true"
}
}
source
share