Example 5, http://java.sun.com/j2ee/tutorial/1_3-fcs/doc/EJBQL4.html
Finder method: findByLeague(LocalLeague league) SELECT DISTINCT OBJECT(p) FROM Player p, IN (p.teams) AS t WHERE t.league = ?1
What I actually wanted to find out is why the following query, a finder of Bean League:
Finder method: findByLeague(LocalLeague league) SELECT DISTINCT OBJECT(t) FROM Team AS t WHERE t.league = ?1
Is NOT working according to my experience.
Why?
According to my cook recipee I gave, one has to reformulate it as
Finder method: findByLeague(LocalLeague league) SELECT DISTINCT OBJECT(t) FROM Team AS t, League AS l WHERE l = ?1 AND t.league = l
But is this working
Best, Philipp
PS:
my original example, where I found that things like this do not work was:
* @ejb.finder
* signature = "java.util.Collection findAffinityData(org.j2ee.examples.cmp.interfaces.UserEntityLocal uid1, org.j2ee.examples.cmp.interfaces.UserEntityLocal uid2)"
* query = "SELECT OBJECT(g) FROM affinityData g WHERE g.userHoldingAd = ?1 AND g.describedUser = ?2"
According to my Cook recipee, one can reformulate it as
* @ejb.finder
* signature = "java.util.Collection findAffinityData(org.j2ee.examples.cmp.interfaces.UserEntityLocal u1, org.j2ee.examples.cmp.interfaces.UserEntityLocal u2)"
* query = "
SELECT OBJECT(g)
FROM
affinityData g,
userEntity u1,
userEntity u2
WHERE
u1 = ?1 AND
u2 = ?2 AND
g.userHoldingAd = u1 AND
g.describedUser = u2"
I tried it out, and it is NOT working.
What works perfectly is:
* @ejb.finder
* signature = "java.util.Collection findAD(ch.minick.j2ee.examples.cmp.interfaces.UserEntityLocal u1, ch.minick.j2ee.examples.cmp.interfaces.UserEntityLocal u2)"
* query = "SELECT OBJECT(ad) FROM userEntity u1, IN(u1.adsOfUser) ad, userEntity u2 WHERE u1 = ?1 AND u2 = ?2 AND ad.describedUser = u2 "
During testing this, I found a sutl Xdoclet issue:
- If you by accident add an @ejb.persistence tag to an @ejb.relation, this may just result in the relation not working in both sides.....
MORE SURPRISINGLY, what works perfect as well is:
* @ejb.finder
* signature = "java.util.Collection findAD1(ch.minick.j2ee.examples.cmp.interfaces.UserEntityLocal u1, ch.minick.j2ee.examples.cmp.interfaces.UserEntityLocal u2)"
* query = "SELECT OBJECT(ad) FROM userEntity u1, IN(u1.adsOfUser) ad WHERE u1 = ?1 AND ad.describedUser = ?2"
With other words: it seems to me, that the ad.describedUser can only be used, when the ad comes from an IN, not when it comes from
a normal from. Therefore, the above two versions work, and the first does not work.
The example from the J2EE Sun tutorial,
Finder method: findByLeague(LocalLeague league) SELECT DISTINCT OBJECT(p) FROM Player p, IN (p.teams) AS t WHERE t.league = ?1
follows the same schema: the "league" is only applied to something comming out of
an IN, thus as well, my version
Finder method: findByLeague(LocalLeague league) SELECT DISTINCT OBJECT(t) FROM Team AS t WHERE t.league = ?1
does not work.
So much for today,
Best, Philipp
smime.p7s
Description: S/MIME Cryptographic Signature
