首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >grails,mongodb gorm,空嵌入对象

grails,mongodb gorm,空嵌入对象
EN

Stack Overflow用户
提问于 2014-12-19 07:28:37
回答 1查看 700关注 0票数 0

我有两个简单的域类:

代码语言:javascript
复制
class Isa95EquipmentSpecification {

    String equipmentClass
    String equipment
    String description
    Float quantity
    String quantityUOM
    List<Isa95EquipmentSpecificationProperty> equipmentSpecificationProperties

    static embedded = ['equipmentSpecificationProperties']

    static constraints = {
        equipment nullable: true, validator: {val, obj -> if (null == val && null ==    obj.equipmentClass) return ['bothNullable']}
        equipmentClass nullable: true, validator: {val, obj -> if (null == val && null == obj.equipment) return ['bothNullable']}
        description nullable: true
        quantity nullable: true
        quantityUOM nullable: true  
    }
}

和子域:

代码语言:javascript
复制
class Isa95EquipmentSpecificationProperty {
    String name
    String description
    String value
    String valueUOM
    Double quantity
    String quantityUOM

    static constraints = {
        name nullable: false
        description nullable: true
        value nullable: false
        valueUOM nullable: false
        quantity nullable: true
        quantityUOM nullable: true
    }
}

我希望构建一个带有嵌入属性的复合文档,我可以保存它,只在父程序上运行save()操作,但是它不能工作。

我尝试在grails控制台上运行:

代码语言:javascript
复制
    def prop1 = new isa95.productdefinition.Isa95EquipmentSpecificationProperty(name: 'prop-1', value: 'mad', valueUOM: '-')
def prop2 = new isa95.productdefinition.Isa95EquipmentSpecificationProperty(name: 'prop-2', value: 12.32, valueUOM: 'kilograms')
def spec = new isa95.productdefinition.Isa95EquipmentSpecification(equipment: '41500', description: 'eq-test', equipmentSpecificationProperties: [prop1, prop2])
spec.save(failOnError: true)

脚本运行正常,但在db中我找到了以下内容。我希望找到使用嵌套列表填充的equipmentSpecificationProperies:

代码语言:javascript
复制
{ "_id" : NumberLong(9), "description" : "eq-test", "equipment" : "14500", "equipmentSpecificationProperties" : [ null, null ], "version" : 0 }
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-12-19 17:36:21

指定列表类型:

代码语言:javascript
复制
List<Isa95EquipmentSpecificationProperty> equipmentSpecificationProperties
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27561500

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档