开发者

GORM list() to return superclass objects only

I have a simple object 开发者_JAVA百科hierarchy, and I want to query each of the objects using list(). The problem is that because of polymorphism, Task.list() returns both instances of type Task and ComplexTask.

class Task {
}

class ComplexTask extends Task {
}

I realize I can solve my problem by having a common abstract superclass, or filter results based on returned type, but was wondering if there is a way to use dynamic finders and get back superclass instances only.


Using the default table-per-hierarchy inheritance strategy, you can do something like this:

Task.findAll("from Task as t where t.class = 'Task'")


i think that has to do with lazy loading, because the real instance is not loaded completely not only for relations but also for inheritance.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜