Great, You shouldn't need to access the JoinTable columns simply use
"anyOf()" on the ManyToMany relationship and TopLink will do the joins
for you. If you have non-relation fields on the table then you can
create DirectQueryKeys to represent the fields and then use the "get()"
functionality of the expression.
Using the TopLink Expression Framework is a great option especially in
your case where you want to create dynamic queries.
The TopLink Expression Framework is a specification extension provided
by TopLink. Other Providers may have similar functionality but will use
different interfaces and patterns.
The way you have chosen to create a query is a great way to create a query.
--Gordon
sonavor wrote:
> I was able to solve my ORDER BY issue using the Toplink ExpressionBuilder.
> To do that I had to switch from using -
> javax.persistence.Query q = (
> (oracle.toplink.essentials.ejb.cmp3.EntityManager)
> em.getDelegate()).createQuery(exp, Person.class);
>
> To using a Toplink ReadAllQuery -
> oracle.toplink.essentials.queryframework.ReadAllQuery readAllQuery = new
> ReadAllQuery(Person.class);
>
> Since the ExpressionBuilder, Expression and ReadAllQuery classes are all
> from oracle.toplink.essentials I am locking my solution to Toplink.
>
> Anyway, the dynamic query now works great with the ORDER BY that I wanted.
>
> The Expression building part of my code is identical to the previous
> posting. It is actually in its own method called
> "createAdhocAllPersonQuery". So with my main Expression object named "exp"
> built up the change in the query implementation is as shown below -
>
> Expression exp = createAdhocAllPersonQuery(srchPerson);
>
> ReadAllQuery readAllQuery = new ReadAllQuery(Person.class);
> readAllQuery.addAscendingOrdering("lastName");
> readAllQuery.addAscendingOrdering("firstName");
> readAllQuery.addAscendingOrdering("midInitial");
> readAllQuery.setSelectionCriteria(exp);
> readAllQuery.prepareForExecution();
>
> // Session is from oracle.toplink.essentials.sessions.Session;
> Session session = (
> (oracle.toplink.essentials.ejb.cmp3.EntityManager)
> em.getDelegate()).getActiveSession();
> if (session != null) {
> List<Person> results = (List)
> session.executeQuery(readAllQuery);
> if (results != null) {
> for (Iterator i = results.iterator(); i.hasNext();) {
> Person p = (Person) i.next();
> // do stuff with Person object here
> pList.add(p);
> }
> }
> }
>
>
>