Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[eclipselink-users] Re: Inheritance influences orderBy result

I found the following thread:

http://www.nabble.com/Why-is-getResultList()-grouped-by-Class-even-when-ORDER-BY-is-used--ts20937838.html

the solution is to use a hint:

eclipseLink 1.1

        Query query = entityManager.createQuery(queryBuilder.getQueryString());
        query.setHint("eclipselink.inheritance.outer-join", true);

eclipseLink 1.0 (requires eclipselink.jar on the classpath)

        Query query = entityManager.createQuery(queryBuilder.getQueryString());
        ((org.eclipse.persistence.queries.ObjectLevelReadQuery"))((org.eclipse.persistence.jpa.JpaQuery"))query).getDatabaseQuery()).setShouldOuterJoinSubclasses(true);
        ((org.eclipse.persistence.queries.ObjectLevelReadQuery"))((org.eclipse.persistence.jpa.JpaQuery"))query).getDatabaseQuery()).setIsPrepared(false);

I tested both and they both work,

Martijn

On Mon, Feb 2, 2009 at 9:14 PM, Martijn Morriën <dj.escay@xxxxxxxxx> wrote:
> Hi,
>
> I'm experiencing incorrectly ordered query results, could someone tell
> me if this is a known issue? If it is known, Is there a clean
> workaround?
>
> My model can be resembled by:
>
> Animal with 2 subclasses: Dog and Horse
>
> I query "select a from Animal a order by name asc" and I get ordered
> dogs followed by ordered horses. I would expect a list ordered
> Animals.
>
> When I look at the queries with logging on Finest I notice 2 selects
> to join the tables, the queries already include the order by clause,
> and it seems that the two results are appended.
>
> example result:
>
> Dog: fred
> Dog: jack
> Horse: ed
> Horse: harry
>
> while I expect:
>
> Horse: ed
> Dog: fred
> Horse: harry
> Dog: jack
>
>
> My inheritance strategy is <inheritance strategy="JOINED" />
>
> Thank you,
>
> Martijn
>


Back to the top