在 Grails/Groovy 中加载插件管理器时出错
Error loading plugin manager in Grails/Groovy
当我遇到问题时,我正在处理一个简单的 grails 项目。我做了很多研究,但我还没有找到正确的答案。
我有 3 个域 类,即 Inventory、User 和 Movement 并且它们之间的关系是 一对多 for Inventory and Movement and the User 和 Movement 相同,因此 Movement 几乎处于中间位置。我设法很好地连接了 Inventory 和 Movement,但其他关系显示如下错误。
Error |
Error loading plugin manager: Property [movements] in class [classcom.inventory.User] is a
bidirectional one-to-many with two possible properties on the inverse side.
Either name one of the properties on other side of the relationship [user] or use the
'mappedBy' static to define the property that the relationship is mapped with.
Example: static mappedBy = [movements:'myprop'] (Use--stacktrace to see the full trace)
| Error Forked Grails VM exited with error
这是我的域名类:
用户:
class User {
String userID
String fullName
String position
Department department
String toString(){
fullName
}
static hasMany = [inventories: Inventory, movements: Movement]
static constraints = {
userID blank: false, unique: true
fullName blank: false
position()
department()
movements nullable: true
}
}
运动:
class Movement {
User oldUser
User newUser
Inventory inventoryID
Date movementDate
User userResponsible
//static belongsTo = User
static constraints = {
inventoryID blank: false
oldUser blank: false
newUser blank: false
movementDate()
userResponsible blank: false
}
}
库存:
class Inventory {
String inventoryID
String code
String description
String serial_num
Date purchase_date
byte[] image
Date record_date
String remarks
Type type
Brand brand
User user
static hasMany = [movements: Movement]
String toString(){
"$inventoryID, $type"
}
static constraints = {
inventoryID blank: false, unique: true
code blank: false
description nullable: true, maxSize: 1000
serial_num blank: false
purchase_date()
image nullable: true, maxSize: 1000000
record_date()
remarks nullable: true, maxSize: 1000
type()
brand()
user()
}
}
知道如何解决错误..??
这里的问题是 gorm 无法区分你的 Movements 上的 newUser 和 oldUser class。尝试添加一个 mappedBy 部分并将另一部分添加到您的 hasMany 属性 到您的用户 class,下面是一个应该有效的示例:
class User {
String userID
String fullName
String position
Department department
String toString(){
fullName
}
static hasMany = [inventories: Inventory, movementsByOldUser: Movement, movementsByNewUser: Movement]
static mappedBy = [movementsByOldUser: 'oldUser', movementsByNewUser: 'newUser']
static constraints = {
userID blank: false, unique: true
fullName blank: false
position()
department()
movements nullable: true
}
}
有关一些文档参考,请参阅:http://www.grails.org/doc/2.2.x/ref/Domain%20Classes/mappedBy.html
当我遇到问题时,我正在处理一个简单的 grails 项目。我做了很多研究,但我还没有找到正确的答案。
我有 3 个域 类,即 Inventory、User 和 Movement 并且它们之间的关系是 一对多 for Inventory and Movement and the User 和 Movement 相同,因此 Movement 几乎处于中间位置。我设法很好地连接了 Inventory 和 Movement,但其他关系显示如下错误。
Error |
Error loading plugin manager: Property [movements] in class [classcom.inventory.User] is a
bidirectional one-to-many with two possible properties on the inverse side.
Either name one of the properties on other side of the relationship [user] or use the
'mappedBy' static to define the property that the relationship is mapped with.
Example: static mappedBy = [movements:'myprop'] (Use--stacktrace to see the full trace)
| Error Forked Grails VM exited with error
这是我的域名类:
用户:
class User {
String userID
String fullName
String position
Department department
String toString(){
fullName
}
static hasMany = [inventories: Inventory, movements: Movement]
static constraints = {
userID blank: false, unique: true
fullName blank: false
position()
department()
movements nullable: true
}
}
运动:
class Movement {
User oldUser
User newUser
Inventory inventoryID
Date movementDate
User userResponsible
//static belongsTo = User
static constraints = {
inventoryID blank: false
oldUser blank: false
newUser blank: false
movementDate()
userResponsible blank: false
}
}
库存:
class Inventory {
String inventoryID
String code
String description
String serial_num
Date purchase_date
byte[] image
Date record_date
String remarks
Type type
Brand brand
User user
static hasMany = [movements: Movement]
String toString(){
"$inventoryID, $type"
}
static constraints = {
inventoryID blank: false, unique: true
code blank: false
description nullable: true, maxSize: 1000
serial_num blank: false
purchase_date()
image nullable: true, maxSize: 1000000
record_date()
remarks nullable: true, maxSize: 1000
type()
brand()
user()
}
}
知道如何解决错误..??
这里的问题是 gorm 无法区分你的 Movements 上的 newUser 和 oldUser class。尝试添加一个 mappedBy 部分并将另一部分添加到您的 hasMany 属性 到您的用户 class,下面是一个应该有效的示例:
class User {
String userID
String fullName
String position
Department department
String toString(){
fullName
}
static hasMany = [inventories: Inventory, movementsByOldUser: Movement, movementsByNewUser: Movement]
static mappedBy = [movementsByOldUser: 'oldUser', movementsByNewUser: 'newUser']
static constraints = {
userID blank: false, unique: true
fullName blank: false
position()
department()
movements nullable: true
}
}
有关一些文档参考,请参阅:http://www.grails.org/doc/2.2.x/ref/Domain%20Classes/mappedBy.html