Use this:
// BUILD QUERY
Criteria criteria = new Criteria();
criteria.setDbName( "MyDB" ); // Optional
T1Peer.addSelectColumns( criteria );
T2Peer.addSelectColumns( criteria );
T3Peer.addSelectColumns( criteria );
criteria.addJoin( T1.ID_T1, T2.ID_T1 );
criteria.addJoin( T2.ID_T3, T3.ID_T3 );
// DO SELECT
List result = new LinkedList();
List records = BasePeer.doSelect( criteria, connection ); //
BasePeer.doSelect( criteria );
for( int i = 0; i < records.size(); i++ ) {
Record row = (Record)records.get( i );
// T1
int index = 1;
Object object1 = T1Peer.row2Object( row, index, T1Peer.getOMClass()
);
// T2
index += T1Peer.numColumns;
Object object2 = T2Peer.row2Object( row, index, T2Peer.getOMClass()
);
// T3
index += T2Peer.numColumns;
Object object3 = T3Peer.row2Object( row, index, T3Peer.getOMClass()
);
result.add( new Object[] { object1, object2, object3 } );
}
// SHOW
fof( Iterator it = result.iterator(); it.hasNext(); ) {
Object[] row = (Object[])it.next();
T1 t1 = (T1)row[ 0 ];
T2 t2 = (T2)row[ 1 ];
T3 t3 = (T3)row[ 2 ];
System.out.println( t1 );
System.out.println( t2 );
System.out.println( t3 );
}
-------> Do the same thing for T1.id_t3 = T3.id_t3
Easy, isnt it????
Ive got a framework to do this very easy ;)
Jose Luis Rovira Martin.
Cristian Zoicas
<[EMAIL PROTECTED] Para: [EMAIL PROTECTED]
.sissa.it> cc:
Asunto: How to create a join ?
11/12/2003 13:48
Por favor,
responda a
"Apache Torque
Users List"
Hello all
I've tried to figure out how to use the Criteria class in
order to obtain a statement like
SELECT
*
FROM
T1, T2, T3
WHERE
( T1.id_t1= T2.id_t1 AND T2.id_t3 = T3.id_t3 )
OR
( T1.id_t3 = T3.id_t3 )
but I was not able to do it.
Does anybody has any solution ?
Thank you in advance
Cristian Zoicas
---------------------------------------------------------------------
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]