I am trying to persist a Template object in the app’s database. It’s not giving me any exceptions but I get the default message from Grails for trying to save an object with a null attribute when the same is marked with nullable:false constraint.
Property tempVersion of class Template cannot be null or (default.null.message)
The Template class is the following:
class Template implements Serializable {
Long tempVersion
String name
Type type
Status status
App app
String body
Tester tester
Date date
static constraints = {
name blank:false, maxSize:50
type nullable:false
status nullable:false
app nullable:false
body blank:false, widget:"textarea"
}
static mapping = {
id composite:['id','tempVersion']
tempVersion generator:"sequence", params:[sequence:'SEQ_TEMPLATE_VERSION']
body type:"text"
version false
}
I cannot understand why is that, cause if I specify tempVersion as a primary key along with the default ‘id’, it should never generate a null value! Just as shouldn’t generate a null id.
Anyway, does anybody see what I am doing wrong about that?
Thanks in advance.
You must write custom sequence generator if you want generate value foe composite ID.
Hibernate doesn’t generate values for composite IDs