emmanuel wrote:
If you use Hibernate EntityManager 3.3.x you don't need to declare the event listeners. They are autowired if HSearch is in the classpath
Thanks. I updated a number of jars and seem to be beyond my previous error to a new one:
....
Not a mapped entity: class com.stottlerhenke.predict.service.persistence.Prediction
at org.hibernate.search.query.FullTextQueryImpl.buildSearcher(FullTextQueryImpl.java:323)
at org.hibernate.search.query.FullTextQueryImpl.list(FullTextQueryImpl.java:209)
at com.stottlerhenke.predict.service.persistence.LuceneSearch.searchPredictions(LuceneSearch.java:79)
at com.stottlerhenke.predict.service.persistence.PredictPersistence.searchPredictions(PredictPersistence.java:266)
at com.stottlerhenke.predict.service.persistence.PredictPersistencePredictionTest.testSearchPredictions(PredictPersistencePredictionTest.java:68)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.junit.internal.runners.TestMethodRunner.executeMethodBody(TestMethodRunner.java:99)
at org.junit.internal.runners.TestMethodRunner.runUnprotected(TestMethodRunner.java:81)
at org.junit.internal.runners.BeforeAndAfterRunner.runProtected(BeforeAndAfterRunner.java:34)
at org.junit.internal.runners.TestMethodRunner.runMethod(TestMethodRunner.java:75)
at org.junit.internal.runners.TestMethodRunner.run(TestMethodRunner.java:45)
at org.junit.internal.runners.TestClassMethodsRunner.invokeTestMethod(TestClassMethodsRunner.java:66)
at org.junit.internal.runners.TestClassMethodsRunner.run(TestClassMethodsRunner.java:35)
at org.junit.internal.runners.TestClassRunner$1.runUnprotected(TestClassRunner.java:42)
at org.junit.internal.runners.BeforeAndAfterRunner.runProtected(BeforeAndAfterRunner.java:34)
at org.junit.internal.runners.TestClassRunner.run(TestClassRunner.java:52)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:38)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
.....
So this looks to me like my annotized classes are not being mapped in this full text session. I know they are without the Search capabilities though. Could it be that I'm missing some kind of initialization when I set up my FullTextSession? Here's my code for the Search part:
public class LuceneSearch
{
private static final String HIBERNATE_FILE = "META-INF/persistence.xml";
private QueryParser _parser;
private String[] _stopWords;
private FullTextSession _textSession;
private EntityManager _entityManager;
public LuceneSearch(EntityManager entityMgr)
{
_entityManager = entityMgr;
// Have to use sessions here
try
{
Session session = (Session) _entityManager.getDelegate();
_textSession = Search.createFullTextSession(session);
initialize(null);//use default stop words for now
}
catch (ClassCastException ce)
{
// this error supposedly should not get thrown as getDelegate()
// supposedly always returns a Session, but just in case.
// (this was from examples on the web and the #hibernate channel so
// needs to be verified
ce.printStackTrace();
// TODO: Wrap it up and do something else with it
throw ce;
}
}
private void initialize(String[] stopWords)
{
if (stopWords != null)
{
// first set up the parser with the new stop words
_parser = new QueryParser("text", new StandardAnalyzer(stopWords));
}
else
{// default stop words
_parser = new QueryParser("text", new StandardAnalyzer());
}
_stopWords = stopWords;
}
public List<Prediction> searchPredictions(String queryStr)
{
// look in text column of predictions
try
{
org.apache.lucene.search.Query luceneQuery = _parser.parse(queryStr);
Query query = _textSession.createFullTextQuery(luceneQuery,
Prediction.class);
return query.list();
}
catch (Exception pe)
{// KKG TODO: Turn this into a better exception
pe.printStackTrace();
}
return null;
}
}
Thanks again,
Kshanti