Criteria使用Hibernate查询无订单

时间:2012-02-22 20:19:07

标签: java hibernate

我正在尝试按日期时间获取具有收集顺序的实体列表,但我不明白。这是我的问题:

trades = session.createCriteria(Trade.class)
    .createAlias("operations", "operations", CriteriaSpecification.INNER_JOIN)
    .add(Restrictions.between("operations.datetime", start, end))
    .addOrder(Order.asc("operations.datetime"))
    .setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY)
    .list();

根据hibernate,这些是查询:

select 
    this_.MUREX_ID as MUREX1_0_1_, 
    this_.PORTFOLIO as PORTFOLIO0_1_, 
    this_.TYPE as TYPE0_1_, 
    operations1_.ID as ID1_0_, 
    operations1_.COMENT as COMENT1_0_, 
    operations1_.DATETIME as DATETIME1_0_, 
    operations1_.GBO_ID as GBO4_1_0_, 
    operations1_.OPERATION as OPERATION1_0_, 
    operations1_.OPERATION_ID as OPERATION6_1_0_, 
    operations1_.OPICS_ID as OPICS7_1_0_, 
    operations1_.STATUS_GBO as STATUS8_1_0_, 
    operations1_.STATUS_MUREX as STATUS9_1_0_, 
    operations1_.MUREX_ID as MUREX10_1_0_ 
from 
    PGT_NY.T_PGT_NY_BLOTTER_TRADES_S this_, 
    PGT_NY.T_PGT_NY_BLOTTER_OPERATIONS_S operations1_ 
where 
    this_.MUREX_ID=operations1_.MUREX_ID and 
    operations1_.DATETIME between ? and ? 
order by operations1_.DATETIME asc

select 
    operations0_.MUREX_ID as MUREX10_1_, 
    operations0_.ID as ID1_, 
    operations0_.ID as ID1_0_, 
    operations0_.COMENT as COMENT1_0_, 
    operations0_.DATETIME as DATETIME1_0_, 
    operations0_.GBO_ID as GBO4_1_0_, 
    operations0_.OPERATION as OPERATION1_0_, 
    operations0_.OPERATION_ID as OPERATION6_1_0_, 
    operations0_.OPICS_ID as OPICS7_1_0_, 
    operations0_.STATUS_GBO as STATUS8_1_0_, 
    operations0_.STATUS_MUREX as STATUS9_1_0_, 
    operations0_.MUREX_ID as MUREX10_1_0_ 
from 
    PGT_NY.T_PGT_NY_BLOTTER_OPERATIONS_S operations0_ 
where 
    operations0_.MUREX_ID in (
        select 
            this_.MUREX_ID 
        from 
            PGT_NY.T_PGT_NY_BLOTTER_TRADES_S this_,
            PGT_NY.T_PGT_NY_BLOTTER_OPERATIONS_S operations1_ 
        where 
            this_.MUREX_ID=operations1_.MUREX_ID and 
            operations1_.DATETIME between ? and ? 
    )

任何帮助都非常有用。

提前致谢!

1 个答案:

答案 0 :(得分:1)

对我来说很好看。你应该得到一个Trade的后面列表,它按操作的日期时间排序,这意味着具有较小日期时间的操作的交易首先出现,然后是具有第二小的操作的交易。

交易对象上的集合按照映射中的说明进行排序。你必须单独对它们进行排序。 Hibernate不会在加载时执行它,因为它会破坏列表,索引集合等的更改跟踪。