Grails应用程序中的非PK字段可以使用数据库序列吗? [英] Is it possible to use a database sequence for a non-PK field in a Grails app?

查看:49
本文介绍了Grails应用程序中的非PK字段可以使用数据库序列吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中,我需要数据库中特定字段的唯一值.该字段的类型必须为Integer.所以我想知道是否可以在该字段中使用序列?以及如何在我的GORM域类中实现它?

In my application i need a unique value for a specific field in the database. This field has to be of type Integer. So i was wondering if it is possible to use a sequence for the field? And how to i implement that in my GORM domain class?

推荐答案

请参阅grails文档,了解如何

See the grails doc on how to use sequences. Depending on the source of the sequence ( (oracle/postgres) sequence number generator type / database table)

static mapping = {
    intField1 generator:'sequence', params:[sequence:'sequence_name']
    intField2 generator:'sequence', params:[table: 'hi_value', column: 'next_value', max_lo: 100]
} 

这篇关于Grails应用程序中的非PK字段可以使用数据库序列吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆