hi michael,

you should not use the name of a relationship in a user alias, in the best case it will have no effect ;)
when you do not define your own alias ojb uses the name of the relationship as 'internal' alias.
i'll have a look at your problem using an empty criteria.


hth
jakob

Michael Hart wrote:

In response to myself:



Criteria main_crit = new Criteria();
main_crit.setAlias("project");
Criteria persons_crit = new Criteria();
persons_crit.setAlias("persons");
persons_crit.addEqualTo("persons.id","2");


main_crit.addAndCriteria(persons_crit);

Query query = new QueryByCriteria(Project.class, main_crit);

Generates this:

SELECT A0.TITLE,A0.DESCRIPTION,A0.ID
FROM PROJECT A0
INNER JOIN PERSON_PROJECT A1 ON A0.ID=A1.PROJECT_ID
INNER JOIN PERSON A2 ON A1.PERSON_ID=A2.ID
WHERE A4.ID = 2



I've just played some more, and putting the main_crit.setAlias at the end of the code block works fine (this is true for the other examples as well):

Criteria main_crit = new Criteria();
Criteria persons_crit = new Criteria();
persons_crit.setAlias("persons");
persons_crit.addEqualTo("persons.id","2");


main_crit.addAndCriteria(persons_crit);

main_crit.setAlias("project");


All works...


So this, plus the other examples, leads me to the following rule-of-thumb:

*********
If you are going to set aliases for a particular set of Criteria, you must
ensure that the name of the first alias you set reflects the name of a
property of the class you wish to query. After that, you may set alias names
to be whatever you wish.
*********

Does that sound right to you, or have I just generated some really weird
test cases?

In any case, I still think it's slightly, slightly buggy... ? (But much
better)

Cheers,

Michael


--------------------------------------------------------------------- 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]



Reply via email to