Why is GORM not saving my object?

后端 未结 2 1282
小鲜肉
小鲜肉 2021-02-05 08:40

If I execute this code in the Grails console:

def p = new Post(title: \"T\");
p.save(flush: true); // or p.save();

Post.count();

GORM is not t

2条回答
  •  攒了一身酷
    2021-02-05 09:19

    Likely some constraint on Post is being violated and thus the object is not being saved. Note that the default behavior of GORM is not to throw on a failed save. You need to either call it like

    p.save(flush: true, failOnError: true);
    

    Or change the behavior globally by adding

    grails.gorm.failOnError=true
    

    to your Config.groovy

提交回复
热议问题