Announcement Announcement Module
Collapse
No announcement yet.
hasOne relationship grails GORM. Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • hasOne relationship grails GORM.

    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.
Working...
X