覆盖 Grails 中的默认序列名称 [英] Override default sequence name in Grails

查看:12
本文介绍了覆盖 Grails 中的默认序列名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何重命名HIBERNATE_SEQUENCE?为每个表生成一个序列(并为这些序列指定特定名称)的方法有据可查,但这不是我要寻找的.

我不介意所有域类共享一个序列.我只需要给它一个特定于应用程序的名称.

解决方案

Hibernate JIRA 中似乎有一个开放特性/增强请求,以使其可全局配置:使默认序列名称全局可配置.我相信,作为一种解决方法,您必须为每个 @Id 字段的所有域类(默认为 hibernate_sequence)将 'generator' 属性设置为相同的名称.参见 oracle 序列创建.

正如您在问题中所暗示的那样,可能有一种方法可以通过对数据库方言进行子类化来做到这一点 - 正如许多人建议的每表序列方法一样.

参见 id 生成器和 DRY原则

How can I rename HIBERNATE_SEQUENCE? Methods for generating one sequence per table (and giving specific names to those sequences) are well-documented, but that's not what I'm looking for.

I don't mind having one sequence shared by all domain classes. I just need to give it an application-specific name.

解决方案

There appears to be an open feature / enhancement request in the Hibernate JIRA to make this globally configurable: Make the default sequence name globally configurable. I believe, as a workaround, you would have to set the 'generator' attribute to the same name for all domain classes (defaults to hibernate_sequence) for every @Id field. See oracle sequence created.

As you hinted in your question, there might be a way to do this by subclassing your database dialect - as many have suggested for a sequence-per-table approach.

See id generator and DRY principle

这篇关于覆盖 Grails 中的默认序列名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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