I have the following code snippet where in some cases the call to ftQuery.getResultSize() returns > 0 but the ftQuery.list() actually returns an empty list. I have several test cases and only in some cases does this situation arise.
Code:
// wrap Lucene query in a org.hibernate.Query
FullTextQuery ftQuery = fullTextSession.createFullTextQuery(query, returnTypes);
// Log the query we are using
logQuery(ftQuery);
// execute search
retObj = ftQuery.list();
logger.debug("### results size: " + ftQuery.getResultSize() + ", results: " + retObj);
when I output the actual query hibernate is running and run it in TOAD the query works fine given the values from the ID field. I ran the lucene query in Luke and the number of results matches the ones from the sysout above.
I should mention that on my entity the ID is a composite class.
Here is the FieldBridge I wrote for the composite key.
Code:
public class SearchTermsViewIdFieldBridge implements TwoWayStringBridge {
@Override
public String objectToString(Object arg0) {
String retString = null;
if (arg0 instanceof SearchTermsViewId) {
SearchTermsViewId id = (SearchTermsViewId)arg0;
StringBuilder sb = new StringBuilder();
retString = sb.append(id.getSearchRef()).append("_")
.append(id.getSearchRefId()).append("_")
.append(id.getXSearchTermId())
.toString();
}
return retString;
}
@Override
public Object stringToObject(String arg0) {
String[] fields = arg0.split("_");
SearchTermsViewId id = new SearchTermsViewId();
id.setSearchRef(fields[0]);
id.setSearchRefId(fields[1]);
id.setXSearchTermId(fields[2]);
return id;
}
Any suggestions?