开发者

Criteria query with restriction across a joined subclass problem

I have the following graph:

OrderLine
    OrderLineExtension
        OrderLineExtensionA
        OrderLineExtensionB
        OrderLineExtensionC

OrderLine contains a Set of OrderLineExtension.

OrderLineExtension is defined as : @Inheritance(strategy = InheritanceType.JOINED) and is marked as an entity and is abstract

A table is created in the db for each of these classes in the hierarchy.

I'm trying to perform a query where the item name on OrderLine is "item", but where the is orderReferenceNumber "orderRef" in OrderLineExtensionA.

I'm not sure how to traverse from OrderLine to OrderLi开发者_开发百科neExtensionA as there is no java reference from OrderLineExtension to OrderLineExtensionA.

I've so far got this which of course does not work.

filter=DetachedCriteria.forClass(OrderLine.class);
    .add(Restrictions.eq("item", "item"));
    .createCriteria("orderLineExtension")
        .add(Restrictions.eq("orderReferenceNumber", "orderRef"));

This fails as hibernate complains that it cannot find orderReferenceNumber in class orderLineExtension which is true as it's in orderLineExtensionA. But, how do I traverse to the extension? I cannot nest another createCriteria as there is no reference in the superclass to the subclass.

Any help would be appreciated.


Oops, don't worry. This problem is thrown up because I did not realise that a collegue had created the same field in each joined subclass. Hibernate will just go the the first subclass to load the property. This why i was getting the wrong instance back.

Now we have renamed them, it all works fine. Had my head scratching for a while though.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜