还有其他
类似的问题,但没有一个帮助我。
我有一个外部数据库,其中包含"团队"表以及"用户名"和"密码"列。在我的Grails项目中,我想正确地映射我的用户类:
class User {
String username
String passwordHash
static mapping={
table 'team'
version false
passwordHash column: 'password'
id column: 'username'
}
}
我不断收到映射异常:实体映射中的重复列:用户列:用户名(应使用 insert="false" update="false" 映射)。
有什么想法吗?
如果您明确使用列作为标识符,而不是 grails 提供的默认标识符id
那么您需要在自定义 ORM 映射中为id
指定字段的名称,如下所示:
class User {
String username
String passwordHash
static mapping={
table 'team'
version false
passwordHash column: 'password'
id column: 'username', name: 'username'
}
}