grails - 在 Grails/Groovy 中加载插件管理器时出错

标签 grails groovy

我正在处理一个简单的 Grails 项目时遇到了问题。我做了很多研究,但还没有找到正确的答案。

问题是我有 3 个域类,即 InventoryUserMovement,它们之间的关系是一对一-many 用于库存移动,对于用户移动也是如此,所以移动 几乎处于中间位置。我成功地连接了库存和移动,但其他关系显示以下错误。

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。尝试添加一个mappedBy部分并将另一部分添加到您的用户类的hasMany属性中,下面是一个应该有效的示例:

    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 - 在 Grails/Groovy 中加载插件管理器时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28313147/

相关文章:

grails - 在遗留数据库之上的 Grail 中建模多对多关系

grails - 创建一个自定义字符串,并在grails中映射到sql

mysql - 如何使用mysql在g​​roovy中存储持续时间

groovy - 应用gradle插件有什么区别

java - Groovy:如何定义带参数的 java 可调用对象并使其可用于 groovy shell?

java - IntelliJ 似乎使用 javac 而不是 groovyc 来处理 groovy 文件?

eclipse - 无法使用 Java 1.8 在 Eclipse 中构建 Grails 应用程序

grails - 使用域模型作为命令对象时如何限制属性绑定(bind)

grails - 以 gsp(grails) 显示图像

web-services - 使用 CXF(实际上是 GroovyWS),我如何生成一个带有一个带有文本节点的子节点的 SOAP header ?