When writing HQL Hibernate Queries, the objects are removed from the database, however they don't appeare to be deleted from the Lucene Index.(I belive this is mentioned in the Hibernate documentation).
What would be the best way to remove these objects from the Lucene directory on disk in this case?
I have tried creating a PostDeleteEvent for every object being deleted from the database. However, debugging the application shows that the FullTextEventListener never receives the PostDeleteEvent. Removing the obects with the Lucene APIs through the IdexWriter work but is inefficient.
The code for creating a PostDeleteEvent follows:
Code:
SessionImpl sessImpl = (SessionImpl) factory.getCurrentSession();
SessionImplementor implementor = sessImpl.getPersistenceContext().getSession();
EntityPersister persister = implementor.getEntityPersister("MetadataValue", mv);
EntityEntry entry = sessImpl.getPersistenceContext().getEntry(mv);
// sessImpl.getPersistenceContext().setEntryStatus(entry, Status.DELETED);
Object[] deletedState = new Object[]
{ mv };
entry.setDeletedState(deletedState);
PostDeleteEvent pdEvent = new PostDeleteEvent(entry, entry.getId(), deletedState,
entry.getPersister(), (EventSource) sessImpl);
Here is the HQL Query:
Quote:
Session session = factory.getCurrentSession();
Query q = session.createQuery("delete from MetadataValue mv where mv.id in (:mvs)");
q.setParameterList("mvs", metaValueIds);
int result = q.executeUpdate();