Search and relationships in sleep mode

I have an object named MyItemBean that can have 0 or more related KeywordBean objects. The resulting classes are as follows:

 @Entity public class MyItemBean { ...stuff... @ManyToMany(targetEntity = KeywordBean.class, cascade = CascadeType.PERSIST) @JoinTable(name = "tbl_item_keyword", joinColumns = @JoinColumn(name = "item_id"), inverseJoinColumns = @JoinColumn(name = "keyword_id")) private List<KeywordBean> keywords = null; ...more stuff... } @Entity public class KeywordBean { ...stuff... private String value=null; ...more stuff... } 

I use JBoss Seam / Hibernate Search to index these objects so that I can perform search queries against them. I would like to be able to search for instances of MyItemBean with a given keyword value. This relationship, however, is unidirectional because I apply KeywordBean objects KeywordBean more than MyItemBean . I looked at the Hibernate Search documentation for examples of how to index relationships, but all the examples they provide are bidirectional. Can someone tell me which annotations I need to apply on MyItemBean.keywords in order to index keyword values ​​correctly?

+4
source share
1 answer

Annotations for use - IndexedEmbedded. It works great with unidirectional associations. The problem may occur if you change the value of KeywordBean. Hibernate Search has no way to update the index for MyItemBean instances that reference the changed KeywordBean. In a bidirectional relationship, you can use @ContainedIn to fix this problem, but you really don't need it. Provided that you are limited to this limitation of updating the index, this might not be a problem. Perhaps your KeywordBean is not changing. Or, if it changes, you can re-index all * KeywordBean * s that are manually affected.

- Hardy

+6
source

Source: https://habr.com/ru/post/1332636/


All Articles