GORM在调用beforeInsert方法之前检查约束

时间:2015-11-23 08:21:15

标签: grails gorm aop

GORM的奇怪行为:

    public class Student {
        String fullname;
        String subscriptionIdentity;

       static constraints={

          subscriptionIdentity blank:false,nullable:true // mean that this field should have value in DB
      }

       def beforeInsert(){
         subscriptionIdentity="S"+System.nanoTime();
      }
    }

当我打电话时:

def std=new Student(fullname:"Ahmed OMAR")
std.save();

似乎GORM没有调用beforeInsert(或者在检查约束后调用它) 因为我收到以下错误消息:

  

字段'subscriptionIdentity'上的对象'com.abdennour.Student'中的字段错误:被拒绝的值[null];

0 个答案:

没有答案
相关问题