Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: re[eclipselink-users] ad complex object model in an ordered way

The best solution is probably to just add a getProperty(String) method to
your Thing that returns the property or value for that name.

So instead of,
>> Things.getProperties().get(x).getValue()

You would do,
>> Things.getProperty(itemNames.get(x)).getValue()

You could also add an @OrderBy to the property OneToMany to always order the
properties by the item.

Or you could use a "join fetch" in your query for Thing to join property and
item, and order by the item name.

The reason the native SQL query only returns Thing is that is does not know
the other objects were joined.  You could use a ResultSetMapping to return
multiple objects, but note these would be unrated.  In EclipseLink you can
also use the "eclipselink.join-fetch" query hint to use join fetching on a
native SQL query.



Raven McSmith wrote:
> 
> 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
> 
> 


-----
http://wiki.eclipse.org/User:James.sutherland.oracle.com James Sutherland 
http://www.eclipse.org/eclipselink/
 EclipseLink ,  http://www.oracle.com/technology/products/ias/toplink/
TopLink 
Wiki:  http://wiki.eclipse.org/EclipseLink EclipseLink , 
http://wiki.oracle.com/page/TopLink TopLink 
Forums:  http://forums.oracle.com/forums/forum.jspa?forumID=48 TopLink , 
http://www.nabble.com/EclipseLink-f26430.html EclipseLink 
Book:  http://en.wikibooks.org/wiki/Java_Persistence Java Persistence 
-- 
View this message in context: http://old.nabble.com/read-complex-object-model-in-an-ordered-way-tp28174170p28218462.html
Sent from the EclipseLink - Users mailing list archive at Nabble.com.



Back to the top