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.
精彩评论