0

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

Christian
  • 3,503
  • 1
  • 26
  • 47

1 Answers1

1

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
Hardy
  • 18,659
  • 3
  • 49
  • 65