Search code examples
jpaeclipselink

Eclipselink, index on enumerated collection?


I have an entity (FitableEntity) with an enumerated collection and I'd like to set an index on the enumeration string. This has no effect (no error, no index):

@Enumerated(EnumType.STRING)
@ElementCollection
@Updateable
@Index(table="fitableentity_state", columnNames={"state"})
private Set<FitableEntityState> state = numSet.of(FitableEntityState.Inactive);

I don't get an index on state in the table fitableentity_state as I'd expect.

Is there a way to do this via annotation or is a migration the only choice?

Thanks.


Solution

  • For future reference this is a solution:

       @CollectionTable(indexes={@Index(columnList="state")})
       @Enumerated(EnumType.STRING)
       @ElementCollection(targetClass = FitableEntityState.class)
       @Updateable
       private Set<FitableEntityState> state = EnumSet.of(FitableEntityState.Inactive);
    

    ElementCollection can be refactored out into CollectionTable but for Eclipselink 2.6 this works nicely with

    <property name="eclipselink.ddl-generation" value="drop-and-create-tables" />
    <property name="eclipselink.ddl-generation.output-mode" value="database" />
    

    in persistence.xml