Abid Hussain escribió:
Hallo again,
thanks for the quick answer.
When I add disciplines.moduleName and disciplines.disciplineName as
attributes for the ReportQuery it somehow works:
ReportQueryByCriteria q = QueryFactory.newReportQuery(Module.class,
crit);
q.addOrderByAscending("name");
q.setAttributes(new String[] {
"name", "courseOfStudy", "disciplines.moduleName",
"disciplines.disciplineName" });
OJB generates following SQL:
SELECT
A0.modul_Name,A0.Zuordnung,A0.Haeufigkeit,A1.MODUL_NAME,A1.BEREICH_NAME
FROM MODUL A0 INNER JOIN MODUL_BEREICH A1 ON
A0.modul_Name=A1.MODUL_NAME ORDER BY 1
But there is one major disadvantage about it: The retrieved Modules
occure as often in the resulting collection as they are referenced in
the ModuleDiscipline. E.g., when a Module has three according rows in
the table ModuleDiscipline, it occurs three times in the result of the
query above.
Hi Abid.
But that is the correct behavior for SQL.
I think the Report Query is not designed to get Persistence Object
in his result, i mean Module.class and ModuleDiscipline.class as an
attribute.
With the ReportQuery you can retrieve the columns or attributes
values. I never try get the collection as an attribute in the result.
With QueryByCriteria you can get Module.class object as you know and
then navigate over the disciplines collection using a Iterator.
every object in the collection are ModuleDiscipline.class so you can
access to the attributes and methods.
I don't know if this help you.
Cheers.
Carlos Chávez.
Maybe there is another way to fix this problem?
Best regards,
Abid Hussain
Carlos Chávez schrieb:
Abid Hussain escribió:
Hallo everybody,
for the following problem I didn't find a proper solution:
I'm using the ReportQuery to retrieve data, because the table has
about 25 columns and i only need a few. The problem is, in the
ReportQuery I can only specifiy the fields which I want to retrieve,
but no collections.
I've got the following classes/tables:
<class-descriptor class="modulverwaltung.beans.ojb.Module"
table="MODUL">
<field-descriptor name="name" column="modul_Name"
jdbc-type="VARCHAR" primarykey="true" />
<field-descriptor name="courseOfStudy" column="Zuordnung"
jdbc-type="VARCHAR" />
...
...
<collection-descriptor name="disciplines"
element-class-ref="modulverwaltung.beans.ojb.ModuleDiscipline"
orderby="disciplineName" sort="ASC">
<inverse-foreignkey field-ref="moduleName" />
</collection-descriptor>
</class-descriptor>
<class-descriptor class="modulverwaltung.beans.ojb.ModuleDiscipline"
table="MODUL_BEREICH">
<field-descriptor name="moduleName" column="MODUL_NAME"
jdbc-type="VARCHAR" primarykey="true" />
<field-descriptor name="disciplineName" column="BEREICH_NAME"
jdbc-type="VARCHAR" primarykey="true" />
</class-descriptor>
To retrieve date from the table MODUL, I could do like this:
QueryByCriteria q = new QueryByCriteria(Module.class,
QueryByCriteria.CRITERIA_SELECT_ALL);
q.addOrderByAscending("name");
c = broker.getCollectionByQuery(q);
But then all the fields from the according table would be retrieved,
whereas I only need two fields plus the specified collection.
On the other hand, when I use a ReportQuery in order to retrieve
only the fields I actually need, I can't specify the collection in
the ReportQuery.
Did you try disciplines.moduleName and disciplines.disciplineName
as attributes for the ReportQuery ?
Cheers,
Carlos Chávez.
Anybody got an idea what I can do?
Best regards,
Abid Hussain
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]