Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
RE: [eclipselink-users] Why is getResultList() grouped by Class even when ORDER BY is used?

Hello Christian,

If you set the logging to fine to see the SQL EclipseLink generates, you
would see that when querying on the root of an inheritance hierarchy it will
issue the query first to get all the subclass types.  EclipseLink will then
use these results to determine which subclasses to issue queries on.  So for
instance, you'll see:
  Select type from root_table order by blah
  Select * from subclass1 order by blah
  Select * from subclass2 order by blah
Etc.  The results returned from each query are concatenated and returned,
which is why you will see them ordered by subclass.

EclipseLink has a shouldOuterJoinSubclasses flag that can force these
queries to be done using an outerjoin instead.  This flag can be set on the
ObjectLevelReadQuery, on the descriptor's inheritance policy, or as a query
hint through the eclipselink.inheritance.outer-join hint.  This flag is
false by default unless you are using a cursor or are filtering results
using firstrows or maxresults.

Hope this helps,

Chris

-----Original Message-----
From: eclipselink-users-bounces@xxxxxxxxxxx
[mailto:eclipselink-users-bounces@xxxxxxxxxxx] On Behalf Of t3_chris
Sent: Thursday, December 11, 2008 4:43 AM
To: eclipselink-users@xxxxxxxxxxx
Subject: Re: [eclipselink-users] Why is getResultList() grouped by Class
even when ORDER BY is used?


Hi!

If someone is seeking a solution to a similar problem, the following might
help:

I've now mapped a completely new class named
VendingmachineComponentNumberingHelper to the same table in the DB, but this
new class VendingmachineComponentNumberingHelper doesn't have any
relationship to the original Class-Hierarchy VendingmachineComponent. It
also doesn't have any setters and i do only use it for getting the next
inventoryId. Here's an example of that class:

@Entity
@Table(name = "vendingmachinecomponent")
public class VendingmachineComponentNumberingHelper implements Serializable
{
    private static final long serialVersionUID = 1L;
    
    @Id @GeneratedValue(strategy=GenerationType.IDENTITY)
    @Column(name = "vendingmachinecomponent_rowid", nullable = false)
    private Integer rowid;
        
    @Column(name = "vendingmachinecomponent_inventoryid")
    private Integer inventoryId;
    

    public VendingmachineComponentNumberingHelper() {
       
    }

    public VendingmachineComponentNumberingHelper(Integer
vendingmachinecomponentRowid) {
        this();
        this.rowid = vendingmachinecomponentRowid;
    }

    public Integer getInventoryId() {
        return inventoryId;
    }

    public Integer getRowid() {
        return rowid;
    }
}

With that new class without any inheritance the ordering works as expected.
A somewhat dirty solution, but it works.

If anyone of you has got a better solution, please post!

Best regards,
  christian
-- 
View this message in context:
http://www.nabble.com/Why-is-getResultList%28%29-grouped-by-Class-even-when-
ORDER-BY-is-used--tp20937838p20952358.html
Sent from the EclipseLink - Users mailing list archive at Nabble.com.

_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users



Back to the top