Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/jpa/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jpa Eclipselink,枚举集合上的索引?_Jpa_Eclipselink - Fatal编程技术网

Jpa Eclipselink,枚举集合上的索引?

Jpa Eclipselink,枚举集合上的索引?,jpa,eclipselink,Jpa,Eclipselink,我有一个带有枚举集合的实体(FitableEntity),我想在枚举字符串上设置一个索引。这没有影响(没有错误,没有索引): @枚举(EnumType.STRING) @元素集合 @可更新 @索引(table=“fitableentity\u state”,columnNames={“state”}) 私有集状态=numSet.of(FitableEntityState.Inactive); 在表fitableentity\u state中,我没有像我预期的那样在状态上获得索引 有没有办法通过

我有一个带有枚举集合的实体(
FitableEntity
),我想在枚举字符串上设置一个索引。这没有影响(没有错误,没有索引):

@枚举(EnumType.STRING)
@元素集合
@可更新
@索引(table=“fitableentity\u state”,columnNames={“state”})
私有集状态=numSet.of(FitableEntityState.Inactive);
在表
fitableentity\u state
中,我没有像我预期的那样在状态上获得
索引

有没有办法通过注释实现这一点,或者迁移是唯一的选择


谢谢。

这是一个解决方案,供将来参考:

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

在persistence.xml中,您需要一个用于集合的collectiontable:在没有collectiontable的情况下正确生成集合表(table fitableentity_state,其中包含fitableentity_id(fk)和state列)。添加CollectionTable没有任何效果。是否尝试使用CollectionTable的indexes字段?这不是JPA的工作原理——如果没有额外的配置,JPA永远不会自己创建表。如果您的集合为空,JPA将无法映射任何有效的行集,因为您的表与实体和实体关系不匹配,或者没有数据-其他所有内容都将抛出错误。大多数情况下,您的声明与现有数据库不匹配;这有时会导致看似空的集合,而数据库本身却确实存在rows@specialzt不知道该告诉您什么,使用Eclipselink 2.4,您不需要使用CollectionTable将ElementCollection映射到辅助表。没有错误,一切都按照广告的方式进行,只是无法让索引注释执行我想要的操作。
   @CollectionTable(indexes={@Index(columnList="state")})
   @Enumerated(EnumType.STRING)
   @ElementCollection(targetClass = FitableEntityState.class)
   @Updateable
   private Set<FitableEntityState> state = EnumSet.of(FitableEntityState.Inactive);
<property name="eclipselink.ddl-generation" value="drop-and-create-tables" />
<property name="eclipselink.ddl-generation.output-mode" value="database" />