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

时间:2015-02-04 03:45:44

标签: grails groovy

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

事情是,我有3个域类,即库存用户运动,它们之间的关系是 one-to 广告资源移动 用户移动相同运动几乎处于中间位置。我设法很好地连接了库存和移动,但是其他关系在下面显示了错误。

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()
    }
}

任何想法如何解决错误.. ??

1 个答案:

答案 0 :(得分:2)

这里的问题是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