Hibernate 搜索@IndexedEmbedded
我有类似的情况 这个
@Entity
@Indexed
public class Place {
@Id
@GeneratedValue
@DocumentId
private Long id;
@Field( index = Index.TOKENIZED )
private String name;
@OneToOne( cascade = { CascadeType.PERSIST, CascadeType.REMOVE } )
@IndexedEmbedded
private Address address;
....
}
@Entity
public class Address {
@Id
@GeneratedValue
private Long id;
@Field(index=Index.TOKENIZED)
private String street;
@Field(index=Index.TOKENIZED)
private String city;
@ContainedIn
@OneToMany(mappedBy="address")
private Set<Place> places;
...
}
现在的问题如下: 例如,如果我更改实体 Place 中的 name 字段,哪些实体将被重新索引?
1) 只有名称字段?
2) 整个Place实体?
3) 整个Place实体和用@IndexedEmbedded注释的实体?
我需要的就是第三个。那么如果它不是标准的,是否有任何解决方案可以实现这种行为?
I have a similar situation like this one
@Entity
@Indexed
public class Place {
@Id
@GeneratedValue
@DocumentId
private Long id;
@Field( index = Index.TOKENIZED )
private String name;
@OneToOne( cascade = { CascadeType.PERSIST, CascadeType.REMOVE } )
@IndexedEmbedded
private Address address;
....
}
@Entity
public class Address {
@Id
@GeneratedValue
private Long id;
@Field(index=Index.TOKENIZED)
private String street;
@Field(index=Index.TOKENIZED)
private String city;
@ContainedIn
@OneToMany(mappedBy="address")
private Set<Place> places;
...
}
The problem now is the following:
If I change for example the name field in entity Place which entities are going to be re-indexed?
1) Only the name field?
2) The whole Place entity?
3) The whole Place entity and the entities annotated with @IndexedEmbedded?
The one I need for my purpose would be the third. So if it is not standard, could there be any solution to achieve this behaviour?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
幸运的是,这确实是第三个,所以我很幸运,它按预期工作
Fortunately it's really the third, so I was lucky and it works as expected
您可以使用以下代码手动重新索引 Place 实体
其次,如果您使用 hibernate,您可以在 persistence.xml 中配置 lucene 以自动更新已更改实体的索引
You can use the following code to re-index the Place Entity manually
Secondly if you are using hibernate you can configure lucene in
persistence.xml
to automatically update the indexes of the entities that are changed