开发者

Hibernate: map last row of a @OneToMany relation

开发者 https://www.devze.com 2023-04-08 12:05 出处:网络
I have a relation between element and its names. All historical names as well as the current one are located in table \"element_name\" that has field \"created\". The row last created is the current n

I have a relation between element and its names. All historical names as well as the current one are located in table "element_name" that has field "created". The row last created is the current name of the element.

How could I map the current name of the element as the property of the element?

class Element implements Serializable {

    @OneToMany(fetch = FetchType.LAZY)
    private List<ElementName> historyOfElementNames;

    // What annotations should be used here?
    private ElementName curr开发者_运维技巧entElementName;

    ...
}

Thanks in advance!


An alternative to your solution would be to map all names in a list, sort that list and then get the current name as elementNames.get(elementNames.size() - 1).

To enable this, add the @IndexColumn annotation as well as the actual index column and indices. That way you also get the order of name changes.

Edit: as of Hibernate 3.5 @IndexColumn seems to have been renamed to @OrderColumn.

0

精彩评论

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