Grails save() Domain Object actually does a Select?(Grails save() 域对象实际上做了一个选择吗?)
问题描述
我正在尝试将我发布到我的 groovy 控制器的 JSONObject.我可以传递对象,查看 JSON 数据,然后从中创建一个域对象.当我将其保存以写入数据库时,它会改为执行 Select .
I am trying to take a JSONObject I posted to my groovy controller. I can pass the object, see the JSON data and then create a Domain Object out of it. When I save it to write to the database it does a Select instead.
def save = {
def input = request.JSON
def instance = new Customers(input)
instance.save()
}
这是我的调试 sql 输出
here is my debug sql output
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=?
不知道是什么原因造成的.
Don't know what would be causing this.
推荐答案
看起来你对用户名有一个唯一的限制.Grails 会选择检查唯一性,因为假设读取一行是轻量级操作,并且最好触发唯一性约束违规和异常.
Looks like you have a unique constraint on username. Grails does a select to check uniqueness since assumed that reading one row is a lightweight action and it's preferable to triggering a unique constraint violation and exception.
另一种方法是删除域类中的唯一约束并在数据库中手动添加唯一约束.
An alternative is to remove the unique constraint in the domain class and add the unique constraint manually in the database.
这篇关于Grails save() 域对象实际上做了一个选择吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Grails save() 域对象实际上做了一个选择吗?
基础教程推荐
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01