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
.
精彩评论