File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
A friendly place for programming greenhorns!
Big Moose Saloon
Register / Login
Other Java Products and Servers
XDoclet, JBossQL and EJB QL: Joining multiple tables (2+) possible?
Joined: May 31, 2004
Nov 06, 2004 13:10:00
I'm trying to figure out how I can join multiple tables together in
QL using XDoclet.
Suppose for the moment I have three tables. School, Car and Person.
In my PersonEntityBean I've got the following method:
/** * Returns a related collection of Schools * * @return A Collection of related Schools * @ejb.interface-method * view-type="local" * @ejb.relation * name="School-Person" * role-name="Person-School" * target-ejb="SchoolBean" * target-multiple="no" * target-role-name="School-Person" * cascade-delete="false" * @jboss.target-relation * fk-constraint="true" * related-pk-field="SCHOOL_NUM" * fk-column="SCHOOL_NUM" */ public abstract java.util.Collection getSchools();
But that simply gets me all the schools that that any particular person belongs to.
What I want is a way to retrieve all the people who are in a certain school and drive a particular car.
The SQL would be (approximately)
SELECT personID FROM Person-School, Person-Car WHERE Person-School.personID = Person-Car.personID AND Person-School.schoolID = X AND Person-Car.schoolID = Y
Note that School and Car have no relation to each other at all, asides from simply sharing the non-key personID field.
Is what I'm trying to do possible with CMP EJB QL or JBossQL?
Joined: Mar 06, 2001
Nov 25, 2004 14:30:00
If you have the following relationships defined
schools.persons //school 1 -> (many) person
person.cars // person 1 -> (many) car
then you should be able to define this method in the SchoolBean
Collection findPersonsThatGotoThisSchoolAndDriveThisCar(String schoolName,String model); select object(p) from School as s, in (s.persons) as person , in (p.cars) as car where car.model = ? and s.schoolName = ?
tag to embed this query.
Joined: Dec 01, 2004
Dec 01, 2004 17:07:00
Hi, The answer is very good from my point of view, it helped me a lot, thank you.
And what do you put inside the tag * @jboss:table-name table-name="table" ?
And which are the methods that the CMP includes (get and set)? which table they belong?
It is sorta covered in the
JavaRanch Style Guide
subject: XDoclet, JBossQL and EJB QL: Joining multiple tables (2+) possible?
Lomboz and Jboss relations
Address-has-one-Customer with multiplicity many using foreign-key mapping
Help me out for EJB2.0 CMR fields mapping in XDOCLET.......
M:N relationship in CMP using 2 entity beans
Is there a problem here ?
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2014