Java 使用Hibernate搜索查询枚举(枚举)的索引嵌入列表
我有下面的模型,我正在尝试使用Hibernate搜索进行全文搜索 我需要搜索所有具有UserRole.PROFESSIONIST角色的用户的“about”字段 这就是模型:Java 使用Hibernate搜索查询枚举(枚举)的索引嵌入列表,java,spring,hibernate,lucene,hibernate-search,Java,Spring,Hibernate,Lucene,Hibernate Search,我有下面的模型,我正在尝试使用Hibernate搜索进行全文搜索 我需要搜索所有具有UserRole.PROFESSIONIST角色的用户的“about”字段 这就是模型: @Entity @Indexed public class User { @Id @GeneratedValue Long id; ... String about; @IndexedEmbedded @Enumerated(EnumType.STRING)
@Entity
@Indexed
public class User
{
@Id
@GeneratedValue
Long id;
...
String about;
@IndexedEmbedded
@Enumerated(EnumType.STRING)
@ElementCollection(targetClass = UserRole.class, fetch = FetchType.EAGER)
@JoinTable(name = "user_roles", joinColumns = {@JoinColumn(name = "user_id")})
List<UserRole> roles = new ArrayList<>();
}
我想做的事可能吗?如果是,我做错了什么?由于目标类是一个枚举,您必须向希望搜索的属性添加一个
@Field
注释(嵌入完整实体时不需要这样做,因为它们有自己的子属性可以搜索)
例如:
@IndexedEmbedded
@Field(name="roles", analyze=Analyze.NO, index=Index.YES)
@Enumerated(EnumType.STRING)
@ElementCollection(targetClass = UserRole.class, fetch = FetchType.EAGER)
@JoinTable(name = "user_roles", joinColumns = {@JoinColumn(name = "user_id")})
List<UserRole> roles = new ArrayList<>();
@IndexedEmbedded
@字段(name=“roles”,analyze=analyze.NO,index=index.YES)
@枚举(EnumType.STRING)
@ElementCollection(targetClass=UserRole.class,fetch=FetchType.EAGER)
@JoinTable(name=“user\u roles”,joinColumns={@JoinColumn(name=“user\u id”)})
列表角色=新的ArrayList();
这一点很好,我已经开始对此进行改进。谢谢
org.hibernate.search.exception.SearchException: Unable to find field roles in com.plusimple.core.models.User
@IndexedEmbedded
@Field(name="roles", analyze=Analyze.NO, index=Index.YES)
@Enumerated(EnumType.STRING)
@ElementCollection(targetClass = UserRole.class, fetch = FetchType.EAGER)
@JoinTable(name = "user_roles", joinColumns = {@JoinColumn(name = "user_id")})
List<UserRole> roles = new ArrayList<>();