I perform a query using Hibernate Search / Lucene in the following way:
Code:
final QueryParser parser = new MultiFieldQueryParser(
LuceneConstants.VERSION, mappedClassFields,
new StandardAnalyzer(LuceneConstants.VERSION));
final org.apache.lucene.search.Query luceneQuery =
parser.parse(searchString);
final org.hibernate.Query hibernateQuery =
fullTextSession.createFullTextQuery(
luceneQuery, mappedClasses);
final List list = hibernateQuery.list();
This work well most of the time, but not when the search results in one hit. When I get a search result of one entity, the entity will be filled with null values, as if the entity was not initialized.
I've also stepped through the Hibernate Search code to determine what happens for these cases. From what I can tell, an EntityInfo object gets created from the Lucene index containing the correct values. Later into the process, an EntityKey object is also created using the correct values. Finally an empty proxy is created using these values, and the proxy is still empty when returned back to my code.
I've found a temporary workaround using this code:
Code:
final List list = hibernateQuery.list();
for (int i = 0; i < list.size(); i++) {
final Object object = list.get(i);
if (object instanceof HibernateProxy) {
list.set(i, ((HibernateProxy) object)
.getHibernateLazyInitializer().getImplementation());
}
}
I found by debugging that the lazy initalizer contained the original entity with its correct values. Although this code works, I would prefer not needing to do this.
After looking through the forums, this is the closest I could find, although the entity was correct set up in my code:
viewtopic.php?f=9&t=972543Thanks,
Stig