[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
[eclipselink-users] read complex object model in an ordered way
|
Hi,
I need to read a complex model in an ordered way with eclipselink. The
order is mandantory because it is a huge database and I want to have
an output of a small portion of the database in an eclipse jface
tableview. Trying to reorder it in the loading/quering thread takes
too long and ordering it in the LabelProvider blocks the UI thread too
much time, so I thought if Eclipselink could be used that way, that
the database will order it, it might give me the performance I need.
Unfortunately the object model can not be changed :-(
The model is something like:
@SuppressWarnings("serial")
@Entity
public class Thing implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.TABLE)
private int id;
private String name;
@OneToMany(cascade=CascadeType.ALL)
@PrivateOwned
private List<Property> properties = new ArrayList<Property>();
...
// getter and setter following here
}
public class Property implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.TABLE)
private int id;
@OneToOne
private Item item;
private String value;
...
// getter and setter following here
}
public class Item implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.TABLE)
private int id;
private String name;
....
// getter and setter following here
}
In the jface tableview the y-axis is more or less created with the query
Query q = em.createQuery("SELECT m FROM Thing m ORDER BY m.name ASC");
using the "name" attribute from the Thing objects as label.
In the table view the x-axis is more or less created with the query
Query q = em.createQuery("SELECT m FROM Item m ORDER BY m.name ASC");
using the "name" attribute from the Item objects as label.
Each cell has the value
Things.getProperties().get[x].getValue()
Unfortunately the list "properties" is not ordered, so the combination
of cell value and x-axis column number (x) is not necessarily correct.
Therefore I need to order the list "properties" in the same way as I
ordered the labeling of the x-axis.
And exactly this is the thing I dont know how it is done. So querying
for the Thing objects should return the list "properties" "ORDER BY
name ASC" _but_ of the "Item"s objects.
First ideas with the @OrderBy annotations did not succeed because it
is a cascaded object model.
Then I tried to use
em.createNativeQuery("SELECT * FROM Thing AS a JOIN Thing_Property AS b ON
a.id=b.Thing_ID JOIN Property AS c ON b.properties_ID = c.id JOIN Item
AS d ON c.item_ID = d.id ORDER BY a.name, d.name ", Thing.class);
It works but not in the desired way. Instead of having the Property in
the list properties I get a 1:1 mapping. Meaning that I should have 10
Thing objects with each 100 Property objects in the properties list,
but I have now 1000 Thing objects with each 1 Property objects in the
properties list. Eclipselink doesn't do the grouping.
Can you give me any hints, how to solve this riddle?
Thanks
Raven