Test of selectAccomplices MISSING in Jboss321 documentation:
kutter Aug 4, 2003 3:32 PMI am using the Jboss 3.2.1 documentation. After this I started with a real project, and found that I have problems with a finder method that has an object as parameter.
In your payed documentation there is one example
for this, the finder method selectAccomplices.
Part of your GangsterBean.java is:
public abstract Set ejbSelectAccomplices(Gangster g) throws FinderException;
But a lot is MISSING here...
What is already MISSING, is that you include the
finder in the GangsterHome.java. I did this
as follows:
//new:
Set selectAccomplices(Gangster g) throws FinderException;
Now the hard part starts, for someone who wants
to use the docu. You have to find out that you have
to add:
//new:
public Set ejbHomeSelectAccomplices(Gangster g) throws FinderException {
return ejbSelectAccomplices(g);
}
to the GangsterBean. I cannot see how someone new
to the field can find it out. I lost quite a lot of time.
Then, testing is easy, adding to the CrimePortalTest:
/** Test Organization-Gangster relationship */
public void testAccomplices() throws Exception
{
Gangster yojimbo = gangsterHome.findByPrimaryKey(YOJIMBO);
Set all = gangsterHome.selectAccomplices(yojimbo);
for (Iterator iter = all.iterator(); iter.hasNext();) {
Gangster element = (Gangster) iter.next();
System.out.println(element);
}
}
SIMPLER SOLUTION:
I think, it would anyhow be simpler to do the following:
Add to ejb-jar.xml:
<query-method>
<method-name>findAccomplices2</method-name>
<method-params>
<method-param>org.jboss.cmp2.crimeportal.Gangster</method-param>
</method-params>
</query-method>
<ejb-ql>[CDATA[
SELECT DISTINCT OBJECT(g)
FROM gangster g, IN(g.jobs) j, IN(j.gangsters) accomplice
WHERE g = ?1 AND accomplice <> ?1
]]</ejb-ql>
Add to GangsterHome.java:
Collection findAccomplices2(Gangster g) throws FinderException;
And test as follows:
/** Test Organization-Gangster relationship */
public void testAccomplices2() throws Exception
{
Gangster yojimbo = gangsterHome.findByPrimaryKey(YOJIMBO);
Collection all = gangsterHome.findAccomplices2(yojimbo);
for (Iterator iter = all.iterator(); iter.hasNext();) {
Gangster element = (Gangster) iter.next();
System.out.println(element);
}
}
You should absolutly add this to the docu. My copyright you get for free, and I hope you improve the docu considerably!
For instance, you should deliver the example as Xdoclet
projects, using your Jboss Ide. Took me a while to
learn the tools and reengineer your example at once.
Philipp