In my unit tests entities are inserted into the database and the FullTextIndexEventListener.onPostInsert runs without any errors but I don't get any documents written to my index. All I get is the initial index catalog containing segments.gen and segments_1. Needless to say, my search queries return nothing.
Code:
@Indexed
@Entity
@Table(name = "patient")
public class Patient implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@DocumentId
private Integer id;
@Basic
@Column(unique=true)
@Field(store= Store.YES)
private String personReference;
}
@Service
public class CareProcessService {
@PersistenceContext
private EntityManager em;
@Resource
private PatientRepository patientRepository;
public List<Patient> search(){
FullTextEntityManager fullTextEntityManager = org.hibernate.search.jpa.Search.getFullTextEntityManager(em);
QueryBuilder qb = fullTextEntityManager.getSearchFactory().buildQueryBuilder().forEntity(Patient.class).get();
Query query = qb.keyword().wildcard().onField("personReference").matching("*").createQuery();
javax.persistence.Query persistenceQuery = fullTextEntityManager.createFullTextQuery(query, Patient.class);
List<Patient> result = persistenceQuery.getResultList();
result = em.createQuery("from Patient").getResultList();
result = patientRepository.findAll();
}
}
public interface PatientRepository extends JpaRepository<Patient, Integer>, Serializable {}
However, if I query my entity manager directly (em.createQuery) I get the expected entities in return. I also get expected results when I query JpaRepository (repository.findAll). The entity manager (em) is injected with the @PersistenceContext annotation in my @Service where the above code is executed. I have tried running my setup with both hibernate-search-4.5.1 and hibernate-search-5.0.0, always with the same result.
Code:
Hibernate: insert into patient (ID, CREATED, PERSON_REFERENCE) values (null, ?, ?)
Hibernate: insert into patient (ID, CREATED, PERSON_REFERENCE) values (null, ?, ?)
[2014-08-08 13:09:22,154][DEBUG] Opening IndexReader for directoryProvider patient.Patient
[2014-08-08 13:09:22,186][DEBUG] Closing MultiReader: CacheableMultiReader [subReaders=[StandardDirectoryReader(segments_1:1407487114870)], managers=[org.hibernate.search.indexes.impl.SharingBufferReaderProvider@57ab5b2f]]
[2014-08-08 13:09:22,187][DEBUG] Closing IndexReader: StandardDirectoryReader(segments_1:1407487114870)
Hibernate: select patient0_.ID as ID1_5_, patient0_.CREATED as CREATED2_5_, patient0_.PERSON_REFERENCE as PERSON_R3_5_ from patient patient0_
Hibernate: select patient0_.ID as ID1_5_, patient0_.CREATED as CREATED2_5_, patient0_.PERSON_REFERENCE as PERSON_R3_5_ from patient patient0_
[2014-08-08 13:09:26,115][DEBUG] HSEARCH000108: Shutting down backend for IndexManager 'patient.Patient'
What have I missed?