android - Grails save() 领域对象实际上做一个选择?

标签 android grails groovy save

我正在尝试将我发布到我的 groovy Controller 的 JSONObject。我可以传递对象,查看 JSON 数据,然后从中创建域对象。当我保存它以写入数据库时​​,它改为执行 Select 。

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

这是我的调试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 执行选择以检查唯一性,因为假设读取一行是轻量级操作,并且它比触发唯一性约束违规和异常更可取。

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

关于android - Grails save() 领域对象实际上做一个选择?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5893291/

相关文章:

android - 需要帮助以列表形式显示带有图像的消息文本

grails - 将自定义库添加到Grails项目

xml - 我如何使用 Groovy 的 XmlSlurper 检查元素是否存在?

grails - IntelliJ IDEA 13.1上的Groovy Grape配置

android - 应用程序更新后重复的 Intent 。警报是否存在?

java - 在面向 Oreo 的 Android 应用程序上使用 Android Broadcast

grails - gorm标准可以受实现域类约束吗?

java - 从 Java EE 调用 Groovy 类 + 添加到 jsp

android - youtubeplayer在启动新视频时立即停止

hibernate - 使用 Grails/Hibernate 加入不相关的实体