db-torque-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "William Wong" <william.w...@openwave.com>
Subject RE: Criteria question...
Date Tue, 20 Jan 2004 16:26:24 GMT
Hi Andres,

Which version of Torque are u using? I'm currently running 3.1 and got below
exception when I use your solution:

org.apache.torque.TorqueException: Malformed column name in Criteria order
by: 'RAND() ASC' is not of the form 'table.column'
	at
org.apache.torque.util.BasePeer.throwMalformedColumnNameException(BasePeer.j
ava:2591)
	at org.apache.torque.util.BasePeer.createQuery(BasePeer.java:1242)
	at org.apache.torque.util.BasePeer.createQueryString(BasePeer.java:984)
	at org.apache.torque.util.BasePeer.doSelect(BasePeer.java:1391)
	at org.apache.torque.util.BasePeer.doSelect(BasePeer.java:1368)

The above exception is throwed by below code in BasePeer.java. It is
expecting the orderby to in a column name format.

            for (int i = 0; i < orderBy.size(); i++)
            {
                String orderByColumn = (String) orderBy.get(i);
                if (orderByColumn.indexOf('.') == -1)
                {
                    throwMalformedColumnNameException("order by",
                            orderByColumn);
                }
                String tableName =
                    orderByColumn.substring(0, orderByColumn.indexOf('.'));

Any recommendation? I understand your sql statement 'select *, rand() as rnd
from table order by rnd asc limit 2' will work but it seems the BasePeer is
enforcing the column name as the order by argument.

Thanks and regards,
William
-----Original Message-----
From: Andres Quijano - Rizonet [mailto:andres@rizo.net]
Sent: Monday, January 19, 2004 8:12 PM
To: 'Apache Torque Users List'
Subject: RE: Criteria question...


I use this to get a random row from a table:

Criteria crit = new Criteria();
crit.addAsColumn("rnd", "rand()");
crit.addAscendingOrderByColumn("rnd");
crit.setLimit(1);
YourTableNamePeer.doSelect(crit);

hope it helps

-----Original Message-----
From: William Wong [mailto:william.wong@openwave.com]
Sent: Domingo, 18 de Enero de 2004 10:32 p.m.
To: torque-user@db.apache.org
Subject: Criteria question...


Hi All,

Is there any easy way to convert below Mysql select statement into a
Criteria statement?

select * from name order by rand() limit 1;

Can I use Criteria.CUSTOM to achieve it?

Thank you in advance.

Regards,
William


---------------------------------------------------------------------
To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org


Mime
View raw message