> > select from BOOK,AUTHOR,BOOK B where
> > BOOK.AUTHOR_ID=AUTHOR.AUTHOR_ID AND
> > B.SECOND_AUTHOR_ID=AUTHOR.AUTHOR_ID
>
> Should the query look like this?
>
> SELECT FROM book, author a1, author a2 WHERE
>    book.author_id = a1.id AND
>    book.second_author_id = a2.id
>
> Pls correct me if I am wrong.

Sorry, you are right of course. I misconstructed the example.
The correct code to produce the join would then be

Criteria criteria = new Criteria();
criteria.addJoin(BookPeer.AUTHOR_ID, AuthorPeer.AUTHOR_ID);
String columnName = AuthorPeer.AUTHOR_ID;
  // column name contains now "AUTHOR.AUTHOR_ID"
columnName = columnName.substring(AuthorPeer.TABLE_NAME.length() + 1,
columnName.length());
  // column name contains now "AUTHOR_ID"
criteria.addJoin("a." + columnName, BookPeer.SECOND_AUTHOR_ID);
criteria.addAlias("a", AuthorPeer.TABLE_NAME);

But the question remains whether there is a shorter way to construct the
alias column name than the lines

String columnName = AuthorPeer.AUTHOR_ID;
columnName = columnName.substring(AuthorPeer.TABLE_NAME.length() + 1,
columnName.length());

other than using the explicit String "AUTHOR_ID"

>
> Cheers,
> Alex

Cheers,

     Thomas


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to