Quantcast
Channel: Spring Community Forums - Grails
Viewing all articles
Browse latest Browse all 40

hasOne relationship grails GORM.

$
0
0
I have 2 domain classes

class Pool {
static belongsTo = [dataCenter: DataCenter]
static hasMany = [nodes :Nodes ]
static hasOne = [thresholdRule: Rules ]
static constraints = {
thresholdRule(unique: true, editable: false, display: false)
}
}

class Rules {
Pool pool
}
Now from the default scaffold "create" page , i create a pool and this calls the save action on the Pool controller.
My controller code for save action is as follows :
Pool pool = new Pool(params)
rule = new Rules(some fields)
pool.thresholdRule = rule
rule.pool = pool

pool.save(flush: true)

I keep getting ConstraintViolationException
could not insert: [Rules]; SQL [insert into rules (version, col_down_threshold, grid_down_threshold, pool_id, row_down_threshold) values (?, ?, ?, ?, ?)]; constraint [null]; nested exception is org.hibernate.exception.ConstraintViolationExcepti on: could not insert: [Rules] while trying to create the pool.


Can someone help me see what I am doing wrong, I am kind of new to hibernate.
I have tried not creating the Rule object all together in which case I get the following error .

property [thresholdRule] of class [Pool] cannot be null.

Viewing all articles
Browse latest Browse all 40

Trending Articles