我正在尝试使Hibernate Search索引具有以下关系:
DocVersion * <-> Document2-> DocType
@Indexed
@Entity
public class Document2 implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE)
@Column(name = "doc_uuid")
private long id;
@IndexedEmbedded
@ManyToOne(cascade = CascadeType.MERGE, fetch = FetchType.LAZY)
@JoinColumn(name = "documentType")
private DocType docType;
}
@Indexed
@Entity
public class DocType implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE)
@Column(name = "doctype_id")
private long id;
@Field
@Column(name = "documentType")
private String documentType;
}
因此它是Document2类中的单向@ManyToOne
关系,因为DocType
只是一个代码表。
但是我需要根据cdt的属性(例如document2.docType.documentType
)来查询索引,
WARNING: org.hibernate.search.exception.SearchException: Unable to find field document2.docType.documentType in com.nws.vedica.model.entity.DocVersion
我想念什么?
休眠搜索:5.9.3。最终
答案 0 :(得分:0)
所以我错过了@ContainedIn
,它需要在@IndexedEmbedded
的另一侧。对我来说Document2
:
@ContainedIn
@OneToMany(mappedBy = "document2", cascade = CascadeType.ALL, fetch = FetchType.EAGER)
@org.hibernate.annotations.Cache(
usage = CacheConcurrencyStrategy.READ_WRITE
)
private Set<DocVersion> docVersions;
,并且在DocType
中作为“叶子”根本不需要链接回到Document2
。
希望能帮助到某人