英文:
search field in List @IndexedEmbedded
问题
我有一个实体,其中包含一个实体列表,我在此列表中添加了@IndexedEmbedded
以便能够进行搜索。所以我想搜索所有具有ID 123且属性x等于给定值的实体。我尝试了下面的代码,但出现了以下错误:
> 无法在com.xx.xx.AEntity中找到字段bEntity.x
@Entity
@Indexed
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
public class AEntity implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@Field
private String id;
@IndexedEmbedded
@ElementCollection
private Set<BEntity> bEntity;
}
@Entity
@IdClass(BPK.class)
public class BEntity implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@Field(name = "x_number")
private String x;
@Id
@Field(name = "y_number")
private String y;
}
QueryBuilder queryBuilder = getFullTextEntityManager().getSearchFactory().buildQueryBuilder().forEntity(AEntity.class).get();
Query query = queryBuilder.bool()
.must(queryBuilder.keyword().onField("id").matching("123").createQuery())
.must(queryBuilder.keyword().onField("bEntity.x").matching(str).createQuery())
.createQuery();
英文:
I have an entity that has a list of entities, i added @IndexedEmbedded
in this list to be able to search into it. So i want to search all entities that has the id 123 and the attribute x equals a given value. I tried with the code bellow but i have this error
> Unable to find field bEntity.x in com.xx.xx.AEntity
@Entity
@Indexed
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
public class AEntity implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@Field
private String id;
@IndexedEmbedded
@ElementCollection
private Set<BEntity> bEntity;
}
@Entity
@IdClass(BPK.class)
public class BEntity implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@Field(name = "x_number")
private String x;
@Id
@Field(name = "y_number")
private String y;
}
QueryBuilder queryBuilder = getFullTextEntityManager().getSearchFactory().buildQueryBuilder().forEntity(AEntity.class).get();
Query query = queryBuilder.bool()
.must(queryBuilder.keyword().onField("id").matching("123").createQuery())
.must(queryBuilder.keyword().onField("bEntity.x").matching(str).createQuery())
.createQuery();
答案1
得分: 0
你的字段被称为 bEntity.x_number
,而不是 bEntity.x
:
@Field(name = "x_number")
这就是为什么你会收到这个错误消息。
在你的查询中使用 bEntity.x_number
而不是 bEntity.x
,问题应该会解决。
英文:
Your field is called bEntity.x_number
, not bEntity.x
:
@Field(name = "x_number")
That's why you're getting this error.
Use bEntity.x_number
instead of bEntity.x
in your query and you should be fine.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论