【发布时间】:2020-12-28 18:50:40
【问题描述】:
我将 CKey 类定义为嵌入式 id 类。
我定义了类BEntity,并为复合主键使用了双向字符串字段桥。
我将AEntity 与ManyToOne 与BEntity 的关系定义为类。
@Entity @Indexed
public class AEntity {
@ManyToOne(optional = false) @IndexedEmbedded(depth = 1, includeEmbeddedObjectId = true)
@JoinColumns(value = { @JoinColumn(name = "fk_fId", referencedColumnName = "fId"),
@JoinColumn(name = "fk_sId", referencedColumnName = "sId") }, foreignKey = @ForeignKey(name = "fk_sub"))
private BEntity bEntity;
}
@Entity @Indexed
public class BEntity {
@EmbeddedId @IndexedEmbedded @FieldBridge(impl = CompositeIdBridge.class)
private CKey cKey;
}
@Embeddable @Indexed
public class CKey {
@Field
private String fId;
@Field
private String sId;
}
public class CompositeIdBridge implements TwoWayStringBridge {
@Override
public String objectToString(Object object) {
return String.format("%s.%s", (CKey) object.getFId(), (CKey) object.getSId());
}
@Override
public Object stringToObject(String stringValue) {
String[] compositeIdProperties = stringValue.split("\\.");
return new CKey(compositeIdProperties[1], compositeIdProperties[2]);
}
}
然后,我尝试在实体类AEntity 上进行休眠搜索,但遇到了这个异常:
无法在 AEntity 中找到字段 bEntity.cKey.fId
Query query = getQuery().bool()
.must(getQuery().keyword().onField("bEntity.cKey.fId").matching("111111").createQuery())
.must(getQuery().keyword().onField("bEntity.cKey.sId").matching("222222").createQuery()).createQuery();
FullTextQuery fullTextQuery = getFullTextEntityManager().createFullTextQuery(query, AEntity.class);
【问题讨论】:
标签: hibernate lucene hibernate-search