In the following entity relationship:
<blockquote>
code:
<pre name="code" class="core">
A ----> B
rel / \
C D</pre>
</blockquote>
basically:
B is an abstract class,
an
instanceA can have a
rel that is an
instanceC or and
instanceD Is there a way to use
EJB QL to search for A's who have a (B that is a) C with name='foo'? (where
name is a property on the C entity, not on the B or D)
I'm guessing the answer is no, but i really wish it was yes!
Otherwise I need to refactor this to:
<blockquote>
code:
<pre name="code" class="core">
A ----> C
\ relC
----> D
relD
</pre>
</blockquote>
where only one of the C or D will ever be set,
and to make it worse, there's not only C & D,
there are E and F as well, and maybe more in
the future.
ugliness.
Anyway, if you have any insight, I'd like to hear it.
Things I wished worked:
1. understandably doesn't work...
<blockquote>
code:
<pre name="code" class="core">
SELECT a
FROM com.baz.A a
WHERE a.rel.name = 'foo'
(a.rel "is a" B, with no name, ergo no go)
</pre>
</blockquote>
2. possible new syntax, perhaps too Java-y
<blockquote>
code:
<pre name="code" class="core">
SELECT a FROM com.baz.A a,
IN ((com.baz.C)a.name) c
WHERE c = 'foo'
(adds casting syntax, basically casting to the needed subclass, returning null otherwise)</pre>
</blockquote>
3. a more SQL syntax, adding a function
<blockquote>
code:
<pre name="code" class="core">
SELECT a
FROM com.baz.A a
WHERE CLASS(a.baz) LIKE com.baz.C
AND c = 'foo'
(adds a CLASS keyword)</pre>
</blockquote>
Edit: OUCH. Trying to edit my post, it's spitting me HTML instead of UBB
[ July 17, 2008: Message edited by: Bill Shirley ]