Java Eclipselink以有序的方式读取复杂对象模型

Java Eclipselink以有序的方式读取复杂对象模型,java,eclipse,eclipse-rcp,rcp,eclipselink,Java,Eclipse,Eclipse Rcp,Rcp,Eclipselink,我需要用eclipselink以有序的方式阅读一个复杂的模型。顺序是mandantory,因为它是一个巨大的数据库,我希望在jface tableview中有一小部分数据库的输出。尝试在加载/查询线程中对其进行重新排序花费的时间太长,而在LabelProvider中对其进行排序会占用UI线程太多的时间,因此我认为,如果Eclipselink可以这样使用,那么数据库将对其进行排序,这可能会给我提供所需的性能。很遗憾,无法更改对象模型:-( 该模型类似于: @SuppressWarnings("se

我需要用eclipselink以有序的方式阅读一个复杂的模型。顺序是mandantory,因为它是一个巨大的数据库,我希望在jface tableview中有一小部分数据库的输出。尝试在加载/查询线程中对其进行重新排序花费的时间太长,而在LabelProvider中对其进行排序会占用UI线程太多的时间,因此我认为,如果Eclipselink可以这样使用,那么数据库将对其进行排序,这可能会给我提供所需的性能。很遗憾,无法更改对象模型:-(

该模型类似于:

@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    
}
// Code end
SELECT p FROM Property p WHERE p.thing = ?1 ORDER BY p.item.name
使用Thing对象中的“name”属性作为标签

在表视图中,x轴或多或少是通过查询创建的

Query q = em.createQuery("SELECT m FROM Thing m ORDER BY m.name ASC");
Query q = em.createQuery("SELECT m FROM Item m ORDER BY m.name ASC");
使用项目对象中的“名称”属性作为标签

每个单元格都有一个值

Things.getProperties().get[x].getValue()
不幸的是,列表“属性”没有排序,因此单元格值和x轴列号(x)的组合不一定正确。因此,我需要按照排序x轴标签的方式对列表“属性”进行排序

确切地说,这就是我不知道它是如何完成的。因此,查询thing对象应该返回列表“properties”“ORDER BY name ASC”,但却是“Item”的对象。我的想法类似于使用两个连接进行查询。将事物与Property和Item连接起来,但不知何故,我还无法使其工作


谢谢你的帮助和你的想法来解答这个谜题。

试试
@OrderBy
JPA注释。类似

@OrderBy('name ASC')
@OneToMany(cascade=CascadeType.ALL)
private List<Property> properties = new ArrayList<Property>();
@OrderBy('name ASC'))
@OneToMany(级联=级联类型.ALL)
私有列表属性=新的ArrayList();

也许其他问题的答案可以帮助您:

我认为您可能需要使用另一个查询来获取每个事物的属性列表(按item.name排序)

比如:

@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    
}
// Code end
SELECT p FROM Property p WHERE p.thing = ?1 ORDER BY p.item.name

谢谢!!不幸的是我得到了这个错误:“内部异常:异常[EclipseLink-7217](Eclipse持久性服务-2.0.1.v20100213-r6600):org.Eclipse.Persistence.exceptions.ValidationException异常描述:order by value[name],在实体[class Thing]的元素[properties]上指定,无效。目标实体[class property]上不存在具有该名称的属性或字段。“eclipselink似乎还不知道Item.name中的name字段。但是我将@OrderBy添加到Item.name中,这没有帮助。eclipselink仍然以无序的方式读取列表:”-(抱歉,误解了这个问题。EclipseLink应该支持@OrderBy,但对您的情况没有帮助。不,没有。我找到了一个可以在数据库上运行的SQL查询,但是EclipseLink没有用它构造我的对象。有什么提示吗?选择*FROM Thing作为连接对象\u属性作为a.id=b.Thing\u id连接属性作为b.properties上的c_ID=c.ID在c.Item上以d的形式连接Item_ID=d.ID按a.name、d.name顺序这在JPQL上也必须是可能的,类似于:SELECT*FROM Thing a JOIN a.property c JOIN c.Item d按a.name、d.name顺序连接