gpt4 book ai didi

grails - 使用关系映射时,Grails通过id获取

转载 作者:行者123 更新时间:2023-12-02 15:34:31 24 4
gpt4 key购买 nike

使用这些域类:

class Country {
static hasMany = [states:State]
}

class State {
static belongsTo = [country: Country]
}

我无法通过其ID检索状态
def country = new Country()
def state = new State()
country.addToStates(state)
country.save()

def foundState = State.get(state.id)

foundState为null。从数据库检索状态的正确方法是什么?

最佳答案

您可能在某处无法通过验证。执行.save(failOnError: true),看看是否有异常。

此外,在休眠实际上执行插入操作之前,您将没有ID。要立即触发此操作,请执行.save(flush: true)

关于grails - 使用关系映射时,Grails通过id获取,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13939512/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com