fneron
fneron

Reputation: 1087

Hibernate collection set column as index

I looked into the documentation (hibernate 4.1) . And I'm kind of confuse, I wish to be able to use the annotation @OrderColumn(name="orders_index") in my set Collection (for design purpose). Right now, I'm actually adding manually a orders_index manually in my PersonnalTaskMacro but it's getting a pain in the * (I need to refactor that...). I came accross the @MapKeyColumn(name="orders_number"), but it's not really what I want. How can I achieve this?

@Entity
@Table(name = "PERS_TASK_MACRO_PARAMETER")
public class PersonnalTaskMacroParameter extends Parameter {

    /* .... */

    @OneToMany(cascade = { CascadeType.ALL } , fetch = FetchType.LAZY)
    @JoinTable(name = "PERS_TASK_MACRO_JOIN", 
    joinColumns = { @JoinColumn(name = "MODULE_PARAMETER_ID") }, 
    inverseJoinColumns = { @JoinColumn(name = "PERS_TASK_MACRO_ID") })
    @ForeignKey(name="FK_PERS_TASK_MACRO_PARAM_ID", inverseName="FK_PERS_TASK_MACRO_ID")
    private Set<PersonnalTaskMacro> personnalTaskMacroSet = new HashSet<PersonnalTaskMacro>();

/* .... */
}

Upvotes: 0

Views: 463

Answers (1)

sharakan
sharakan

Reputation: 6901

A Set is not an ordered collection. The documentation you cited points in the right direction: change

Set<PersonnalTaskMacro> personnalTaskMacroSet ...

to

List<PersonnalTaskMacro> personnalTaskMacros ...

You can also use SortedSets to do something similar, but that depends on the sort key being part of the entity that you have a collection of.

Upvotes: 1

Related Questions