- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
出于传统兼容性的原因,我尝试在gorm-standalone 5或grails 3.1.16上将以下代码应用于逻辑
@Id
@GeneratedValue(strategy = GenerationType.TABLE, generator = "book_generator")
@TableGenerator(name="book_generator", table="id_generator", schema="bookstore")
@Column(name = "id", updatable = false, nullable = false)
private Long id;
package helloworld
class Book {
Integer id
String name
String author
static constraints = {
id column: 'book_id'
name blank: false
}
static mapping = {
table 'BOOKTABLE'
version false
// id( generator: 'hilo', params: [table: 'BOOK_SEQ', column: 'next_value', max_lo: 1, initial_value: 1, increment_size: 1 ])
id( generator: 'table', strategy: 'enhanced-table', parameters: [name: 'table_name', value: 'BOOK_SEQ', column: 'next_value', initial_value: 1, increment_size: 1 ])
}
}
最佳答案
要实现您在Grails 3.1.16中尝试执行的操作(使用hibernate4或hibernate5)。首先,通过添加到application.yml
文件来确保在启动时创建了架构。
#Add this to any sample apps if you want the schema
environments:
development:
dataSource:
dbCreate: create-drop
url: jdbc:h2:mem:devDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE;INIT=CREATE SCHEMA IF NOT EXISTS bookstore
// Works in Grails 3.1.16 with Hibernate4 or Hibernate5
class BookGormTableSequence {
String name
String author
static mapping = {
version false
id column: "book_id",
generator: "enhanced-table",
params: [schema: "BOOKSTORE", table_name: "BOOK_SEQ", initial_value: 300]
}
}
//Works in Grails 3.1.16, 3.2.x, and 3.3.x
class BookGormSequence {
String name
String author
static mapping = {
version false
id column: "book_id", generator: "sequence", params: [sequence_name: "bookGormseq", initial_value: 200]
}
}
generator: "enhanced-table"
。 “序列”生成器将在所有测试版本中工作。一旦Gorm 6.1.x可用,则JPA映射为
supported。这意味着您的原始语法几乎不需要修改就可以使用。
// Table Sequence as in your question
import javax.persistence.*
@Entity
class BookJpaTableSequence {
@Id
@TableGenerator(name="book_generator", table="BOOK_SEQ", schema="bookstore", initialValue = 55)
@GeneratedValue(strategy = GenerationType.TABLE, generator = "book_generator")
@Column(name = "book_id", updatable = false, nullable = false)
Long id
String name
String author
}
// Normal Sequence - Should be more performant.
import javax.persistence.*
@Entity
class BookJpaSequence {
@Id
@SequenceGenerator(name = "book_generator", sequenceName = "bookJpaSeq", initialValue = 500)
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "book_generator")
@Column(name = "book_id", updatable = false, nullable = false)
Long id
String name
String author
}
关于spring-boot - 如何在gorm-standalone/grails上使用TableGenerator策略,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48269106/
我在使用 Go 进行应用程序开发,我使用 gorm 库连接到数据库。我看到 gorm 有 2 个库 github.com/jinzhu/gorm和 gorm.io/gorm . 我不知道该用哪个。它们
我是 Gorm 的新手。我正在尝试进行级联删除,如果我删除一个用户,则与该用户关联的角色(属于)、个人资料(有一个)和书籍(一对多)也将被删除。 我在下面设置了我的模型,但级联似乎不起作用。当我删除我
使用 Jinzhu 的 GORM 包,顺便说一句,我现在有这个结构: type User struct { gorm.Model // The Users username U
Golang 的 GORM 库支持复合主键。但是如何从相关模型中引用它们呢? 例如,假设我有一个 User 和一个 Note 模型: type User struct { Organizati
我正在尝试使用 Grails 项目作为插件,基本上将我的域类放在插件中,然后在多个 Grails 项目中使用它们。 我已经这样做了: grails 创建应用程序网页 grails 创建应用程序插件 在
Golang 的 GORM 库支持复合主键。但是如何从相关模型中引用它们呢? 例如,假设我有一个 User 和一个 Note 模型: type User struct { Organizati
如何省略来自 gorm.Model 的列。例如。创建日期、修改日期。 考虑以下模型: type User struct{ gorm.Model Firstname string
当我在 Grails 中执行 domainObj1 == domainObj2 时,对象是按 ID 进行比较的吗?如果不是,如何比较? 最佳答案 首先,您需要了解 GORM/Grails 在 equa
目前正在为此苦苦挣扎。 我希望能够使用抽象域类来使我能够使用一些通用代码来执行一些常用操作。 我的问题是很多 GORM 操作都是域类上的静态方法,这使得它变得困难。想知道这些方法是否有任何非静态等价物
我有一个结构/模型 type User struct { gorm.Model Name string `gorm:"unique;not null"
我想创建一组在我的应用程序中使用的 gorm 类型。所以我想用我的类型定义一个 map gorm.DB作为键和空的结构{}作为标志: var ( autoMigrations map[gorm
有表 customer_account (postgres) 是从 YII2 迁移过来的。 数据链接: CREATE TABLE public.test_table ( id INTEGER PR
我有一个域对象,它已经有一个名为 versions 的属性,所以我想给内置的 version 属性一个不同的名称(在 GORM 中用于乐观锁定)。例如,我想将其称为 updateCount。 请注意,
我有一个普通的 Grails 3.3.2 应用程序。我可以使用 gradle testintegrationTest 很好地运行测试。但是,当我尝试右键单击并在 IntelliJ 中运行测试类或单个测
除了这样做对性能的明显影响之外,还有什么好的技术原因 不是 设置 grails.gorm.autoFlush = true和 grails.gorm.failOnError = true在 Confi
GORM 似乎不尊重我基于外键关联表的尝试,而我的主键关联有效。 我有 3 个结构,它们与 3 个单独的数据库表相关联。它们的关系如下: Inventory.CustID 与 Customer.Cus
我有一个像这样的 golang 结构的表: Order { ID TransactionID Transaction } Transaction { ID ProfileID
我正在使用 Gorm,对如何从模型中检索嵌套的 SubComments 有一些疑问。我遇到的问题是评论嵌套了两层深,即 Comment.SubComments 没有加载。我是否遗漏了 Preload
我正在尝试使用 golang gorm 创建一个自我引用的一对多关系。每个用户可以创建多个其他用户 (Created),但一个用户始终由另一个用户创建 (UserID)。 type User stru
假设我有 2 个表,它们共享一些列名,例如: table_1 - id - created_at - deleted_at - name - color table_2 - id - created_
我是一名优秀的程序员,十分优秀!