gpt4 book ai didi

grails - 对Grails中的Elastic Search结果调用findBy…时发生TransientObjectException

转载 作者:行者123 更新时间:2023-12-02 14:49:56 25 4
gpt4 key购买 nike

我已经在运行grails 2.5.0的grails项目中成功设置了 flex 搜索插件。我可以搜索并获得结果。但是对结果的某些操作是不可能的,例如在一个域上调用通过GORM的findBy与另一个域进行交互的方法...

鉴于Foo类

class Foo {
static searchable = true

def getBars() {
return Bar.findAllByFoo(this)
}
}

酒吧类
class Bar {
Foo foo
static searchable = true
}

下面的第三行将导致TransientObjectException
def result = Foo.search("Some parameter")
def foo = result.searchResults.first()
def bars = foo.bars //Fails

异常(exception)
object references an unsaved transient instance - save the transient instance before flushing: org.example.Foo. Stacktrace follows:
Message: object references an unsaved transient instance - save the transient instance before flushing: org.example.Foo
Line | Method
->> 105 | methodMissing in org.grails.datastore.gorm.GormStaticApi

在网络上搜索此问题会产生许多与GORM保存操作相关的命中情况,我想这不是问题。如果该对象不是从 flex 搜索结果中提取的,这将非常好,为什么我认为此问题与插件有关。
def foo = Foo.get(1)
def bars = foo.bars //Works

最佳答案

检查official documentation:

To map a parent/child relationship, the child element must either contain the parent element as a component or reference it as a referenced document. This component must be mapped as a parent in the child element.

Example:

class ParentElement {

}

class EmbeddingChild {
ParentElement parentElement

static searchable = {
parentElement parent: true, component: true
}
}

class ReferencingChild {
ParentElement parentElement

static searchable = {
parentElement parent: true, reference: true
}
}


还有 good example at the end

关于grails - 对Grails中的Elastic Search结果调用findBy…时发生TransientObjectException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35505586/

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