查询单向多点索引

时间:2018-11-23 13:52:00

标签: hibernate lucene hibernate-search

我正在尝试使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。最终

1 个答案:

答案 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

希望能帮助到某人