Hi Thomas,
That's OK.
But in the case of a ReportQueries, you can't use your "real" SQL query.
Is the example in FAQ still right if you consider your post?
FAQ example:
----code----
String sql =
"SELECT A.Artikel_Nr FROM Artikel A, Kategorien PG"
+ " WHERE A.Kategorie_Nr = PG.Kategorie_Nr"
+ " AND PG.Kategorie_Nr = 2";
// get the QueryBySQL
Query q2 = QueryFactory.newQuery(Article.class, sql);
Iterator iter2 = broker.getIteratorByQuery(q2);
// or
Collection col2 = broker.getCollectionByQuery(q2);
----code----
Thanks
Sylvain
-----Message d'origine-----
De: Mahler Thomas [mailto:[EMAIL PROTECTED]
Date: jeudi, 20. mars 2003 09:29
�: 'OJB Users List'
Objet: RE: how to send a real SQL query to OJB
Hi Sylvain,
the methods broker.getCollectionByQuery(...) and
broker.getObjectByQuery(...)
return fully materialized objects.
Thus OJB expects a query fed into those method to contain all mapped columns
of the underlying table.
If you want to use Queries to not produce full objects but only a data view
as with your "select workstationName from Workstation" query,
you will have to use OJB ReportQueries.
Here is an example:
Criteria crit = new Criteria();
Collection results = new Vector();
ReportQueryByCriteria q = QueryFactory.newReportQuery(
ProductGroup.class, crit);
// define the 'columns' of the report
q.setColumns(new String[] { "groupName",
"sum(allArticlesInGroup.stock)",
"sum(allArticlesInGroup.price)" });
crit.addGroupBy("groupName");
Iterator iter = broker.getReportQueryIteratorByQuery(q);
HTH,
Thomas
> -----Original Message-----
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
> Sent: Thursday, March 20, 2003 8:59 AM
> To: [EMAIL PROTECTED]; [EMAIL PROTECTED]
> Subject: RE: how to send a real SQL query to OJB
>
>
> Hi Armin,
>
> I have seen the FAQ. Thanks.
>
> But it doesn't work for me.
>
> My SQL query is "select workstationName from Workstation".
> From my database query analyzer, this query retrieves 36 rows.
>
> In OJB I try:
> ----code----
> String sql = "select workstationName from Workstation";
>
> Query query = QueryFactory.newQuery(Workstation.class, sql);
>
> try {
> broker.beginTransaction();
> Collection col = broker.getCollectionByQuery(query);
>
> int size = col.size();
> System.out.println(size);
>
> broker.commitTransaction();
> } catch (Throwable t) {
> broker.abortTransaction();
> t.printStackTrace();
> }
> ----code----
>
> The problem is that the size of the collection is 0!
> OJB doesn't retrieve anything!
>
> But if I try the query "select * from Workstation", it works!!
>
> Have you an idea what's the problem?
>
> I'm using OJB 0.9.5.
>
>
> Thanks
> Sylvain
>
>
> -----Message d'origine-----
> De: Armin Waibel [mailto:[EMAIL PROTECTED]
> Date: mercredi, 19. mars 2003 16:12
> �: OJB Users List
> Objet: Re: how to send a real SQL query to OJB
>
>
> Hi Sylvain,
>
> see FAQ
> http://db.apache.org/ojb/faq.html
>
> topic "Is it possible to perform my own sql-queries in OJB?"
> + "Can I directly obtain a java.sql.Connection within OJB?"
>
> regards,
> Armin
>
> ----- Original Message -----
> From: <[EMAIL PROTECTED]>
> To: <[EMAIL PROTECTED]>
> Sent: Wednesday, March 19, 2003 4:05 PM
> Subject: how to send a real SQL query to OJB
>
>
> Hello,
>
> I have a String variable which contains a real SQL query like this:
> "SELECT distinct(workstationName) FROM Workstation w,
> WntWorkstation t,
> Package p, Package_Workstation r WHERE (w.workstationName like '%' or
> w.workstationName is NULL) order by w.workstationName"
>
> How can I send this query (as written above) to OJB?
>
> Thanks
> Sylvain
>
> ---------------------------------------------------------------------
> 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]
>
>
> ---------------------------------------------------------------------
> 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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]