tags:

views:

174

answers:

2

I have a simple object 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.

+2  A: 

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

Task.findAll("from Task as t where t.class = 'Task'")
ataylor
+1. Thanks - you are right, I should have mentioned I am trying to use tablePerHierarchy=false, although I can probably switch to the other other one, since I expect to have relatively few superclass objects.
Jean Barmash
A: 

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.

nils petersohn