【问题标题】:Is it possible to use a database sequence for a non-PK field in a Grails app?是否可以将数据库序列用于 Grails 应用程序中的非 PK 字段?
【发布时间】:2012-05-30 10:03:56
【问题描述】:

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

【问题讨论】:

    标签: database grails grails-orm sequence


    【解决方案1】:

    请参阅 grails 文档以了解如何use sequences。取决于序列的来源((oracle/postgres)序列号生成器类型/数据库表)

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

    【讨论】:

    • 感谢您的回复!效果很好!
    猜你喜欢
    • 1970-01-01
    • 2011-05-01
    • 2015-12-22
    • 1970-01-01
    • 2015-02-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多