简体   繁体   English

Hibernate 搜索 - 问题索引嵌入/关联对象

[英]Hibernate Search - issue indexing embedded / associated objects

I'm having difficulty adding index fields to embedded objects using hibernate search.我在使用 hibernate 搜索将索引字段添加到嵌入式对象时遇到困难。

I have a simple example whereby a Company can have many CompanyAddress(es) - example of my setup is shown below:我有一个简单的例子,一个公司可以有很多 CompanyAddress(es) - 我的设置示例如下所示:

Company.java公司.java

@Data
@Entity
@Table(name="COMPANY")
@Indexed
public class Company implements Serializable {

    ...

    @OneToMany(mappedBy="company", fetch=FetchType.LAZY, 
               cascade=CascadeType.ALL, orphanRemoval = true)
    @JsonManagedReference
    @IndexedEmbedded(depth=1, includePaths={"postalCode"})
    private Set<CompanyAddress> address;

    ...

}

CompanyAddress.java公司地址.java

@Data
@NoArgsConstructor
@Entity
@Table(name="COMPANY_ADDRESS")
@Indexed
public class CompanyAddress implements Serializable {

    @ManyToOne
    @JoinColumn(name="company_id", referencedColumnName = "id")
    @JsonBackReference
    @ContainedIn
    private Company company;

    @Column(name="POSTAL_CODE", length=10)
    private String postalCode;

}

When I try to index I get the following error:当我尝试索引时,出现以下错误:

Caused by: javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory; nested exception is org.hibernate.search.exception.SearchException: HSEARCH000216: Found invalid @IndexedEmbedded->paths elements configured for member 'address' of class 'com.example.model.Company'. The invalid paths are [address.postalCode]

Now if I swap the @Contained and @IndexedEmbedded to be on the address object I can index and find companies from addresses however I would wish to be able to include address fields in the Company index.现在,如果我将 @Contained 和 @IndexedEmbedded 交换到地址 object 上,我可以根据地址编制索引并查找公司,但是我希望能够在公司索引中包含地址字段。

I'm using hibernate search 5.11.11.Final.我正在使用 hibernate 搜索 5.11.11.Final。

Any guidance would be much appreciated.任何指导将不胜感激。

Ok I solved this - adding an @Field annotation to the postalCode attribute meant the field was indexed and the error didn't occur.好的,我解决了这个问题 - 向 postalCode 属性添加 @Field 注释意味着该字段已被索引并且没有发生错误。

Hopefully this will be useful for anyone else with similar problems.希望这对其他有类似问题的人有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM