Christian
Christian

Reputation: 4094

How to handle collection updates with Hibernate Search

I am executing an update with Entitymanager as follows:

Query query1 = em.createQuery("update user u set u.changed = true where u.changed is null");
query1.executeUpdate();

changed is an annoted field as follows:

@Column(nullable = false)
@Field(analyzer=@Analyzer(impl=StandardAnalyzer.class))
@FieldBridge(impl=org.hibernate.search.bridge.builtin.BooleanBridge.class)
private Boolean changed = false;

After the update the lucene index does not get updated. What do I have to do, that the lucene index gets also updated?

Kind regards Christian

Upvotes: 0

Views: 327

Answers (1)

Hardy
Hardy

Reputation: 19119

Executing a SQL query is bypassing the session life cycle. For this reason the automatic index update won't work. You basically have two options:

  1. Load the affected entities via a criteria query, modify them and then save them (all within the session of course)
  2. Manually index the entities via the Search indexing API. Same idea here though, you need to select/query for the right entities to be indexed

Upvotes: 1

Related Questions