Sleeping criterion problems with order and joins

I have a dormant Contract object that has a set of "ContractVersions" (one-to-many mapping). Here's a short display:

<class name="Contract">
    <set name="versions" order-by="version_id" mutable="false" lazy="false" fetch="join">
        <key column="contract_id" not-null="true"/>
        <one-to-many class="ContractVersion"/>
    </set>
</class>

      

Then I create a criterion that searches for a contract and you want to order the results by date:

criteria.addOrder(Order.desc("createdAt"));

      

However, when I look at the generated SQL, I see a problem. Hibernate uses left outer join to select versioning contracts and adds both orderings:

... order by version4_.version_id, this_.created_at desc ...

      

For me, ordering by date is more important. Is there a way to solve this problem?

+3


source to share





All Articles