微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

android – Grails save()域对象实际上是一个Select吗?

我试图把我发布到我的groovy控制器的JSONObject.我可以传递对象,查看JSON数据,然后从中创建一个域对象.当我保存它以写入数据库时​​,它会执行Select.

def save = {
    def input = request.JSON
    def instance = new Customers(input)
    instance.save()
}   

这是我的debug sql输出

Hibernate: 
select
    this_.customers_id as customers1_237_0_,
    this_.customers_default_address_id as customers2_237_0_,
    this_.customers_dob as customers3_237_0_,
    this_.customers_email_address as customers4_237_0_,
    this_.customers_email_address2 as customers5_237_0_,
    this_.customers_fax as customers6_237_0_,
    this_.customers_firstname as customers7_237_0_,
    this_.customers_gender as customers8_237_0_,
    this_.customers_lastname as customers9_237_0_,
    this_.customers_membertype as customers10_237_0_,
    this_.customers_memo1 as customers11_237_0_,
    this_.customers_mname as customers12_237_0_,
    this_.customers_newsletter as customers13_237_0_,
    this_.customers_password as customers14_237_0_,
    this_.customers_point_date as customers15_237_0_,
    this_.customers_telephone as customers16_237_0_,
    this_.customers_total_points as customers17_237_0_,
    this_.customers_username as customers18_237_0_ 
from
    customers this_ 
where
    this_.customers_username=?

不知道是什么原因造成的.

解决方法:

看起来您对用户名有唯一约束. Grails执行select来检查唯一性,因为假设读取一行是轻量级动作,并且最好触发唯一约束违例和异常.

另一种方法删除域类中的唯一约束,并在数据库中手动添加唯一约束.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐