本文介绍了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文档,了解如何使用序列.取决于序列的来源((oracle/postgres)序列号生成器类型/数据库表)
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字段可以使用数据库序列吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!