-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 8 posts ] 
Author Message
 Post subject: Exception trying simple Lucene query
PostPosted: Wed Mar 28, 2007 2:57 pm 
Newbie

Joined: Wed Mar 28, 2007 2:51 pm
Posts: 16
Hi,
I updated to all the compliant versions and jars and am trying a simple lucene query over my models, which I store/retrieve already.

Here is the code:

Code:
            FullTextSession fullTextSession = Search.createFullTextSession(
                    session);
            org.apache.lucene.queryParser.QueryParser parser = new QueryParser(
                    defaultField, new StopAnalyzer());

            org.apache.lucene.search.Query luceneQuery = parser.parse(query);
            org.hibernate.Query fullTextQuery = fullTextSession.createFullTextQuery(
                    luceneQuery);

            List result = fullTextQuery.list(); //return a list of managed objects

            return result;


Other useful snips:
Code:
      <property name="current_session_context_class">thread</property>
      <property name="hibernate.search.default.indexDir">C:\hibernate\indexes</property>
      <property name="hibernate.search.default.directory_provider">org.hibernate.search.store.FSDirectoryProvider</property>


I am running hibernate in local thread, not container.

Thanks for any tips.

Darren

org.hibernate.HibernateException: getListeners is not valid without active transaction
at org.hibernate.context.ThreadLocalSessionContext$TransactionProtectionWrapper.invoke(ThreadLocalSessionContext.java:297)
at $Proxy14.getListeners(Unknown Source)
at org.hibernate.search.util.ContextHelper.getSearchFactoryBySFI(ContextHelper.java:22)
at org.hibernate.search.query.FullTextQueryImpl.list(FullTextQueryImpl.java:145)
at mil.darpa.tn.model.ReportModelFactory.searchReports(ReportModelFactory.java:127)
at mil.darpa.tn.model.ReportFactory.searchReports(ReportFactory.java:82)
at mil.darpa.tn.TNMain.main(TNMain.java:89)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.apache.tools.ant.taskdefs.ExecuteJava.run(ExecuteJava.java:202)
at org.apache.tools.ant.taskdefs.ExecuteJava.execute(ExecuteJava.java:134)
at org.apache.tools.ant.taskdefs.Java.run(Java.java:710)
at org.apache.tools.ant.taskdefs.Java.executeJava(Java.java:178)
at org.apache.tools.ant.taskdefs.Java.execute(Java.java:84)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:275)
at org.apache.tools.ant.Task.perform(Task.java:364)
at org.apache.tools.ant.Target.execute(Target.java:341)
at org.apache.tools.ant.Target.performTasks(Target.java:369)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1216)
at org.apache.tools.ant.Project.executeTarget(Project.java:1185)
at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:40)
at org.apache.tools.ant.Project.executeTargets(Project.java:1068)
at org.apache.tools.ant.module.bridge.impl.BridgeImpl.run(BridgeImpl.java:240)
at org.apache.tools.ant.module.run.TargetExecutor.run(TargetExecutor.java:293)
at org.netbeans.core.execution.RunClassThread.run(RunClassThread.java:131)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 28, 2007 3:38 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Sounds to me like you are using a transaction bound session outside a transaction, that's bad :-)

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 28, 2007 3:39 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
if you want to do that, I would recommend the ManagedSessionContext

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 28, 2007 4:01 pm 
Newbie

Joined: Wed Mar 28, 2007 2:51 pm
Posts: 16
I am new to this, so thanks for the tips. I read the session/transaction docs and demarcated my code like this to get past that exception:

Code:
           session.beginTransaction();
            FullTextSession fullTextSession = Search.createFullTextSession(
                    session);
            org.apache.lucene.queryParser.QueryParser parser = new QueryParser(
                    defaultField, new StopAnalyzer());

            org.apache.lucene.search.Query luceneQuery = parser.parse(query);
            org.hibernate.Query fullTextQuery = fullTextSession.createFullTextQuery(
                    luceneQuery);

           
            List result = fullTextQuery.list(); //return a list of managed objects
            session.getTransaction().commit();



But I reached another exception I do not understand yet.



org.hibernate.HibernateException: Lucene event listener not initialized
at org.hibernate.search.util.ContextHelper.getSearchFactoryBySFI(ContextHelper.java:31)
at org.hibernate.search.query.FullTextQueryImpl.list(FullTextQueryImpl.java:145)
at mil.darpa.tn.model.ReportModelFactory.searchReports(ReportModelFactory.java:128)
at mil.darpa.tn.model.ReportFactory.searchReports(ReportFactory.java:82)
at mil.darpa.tn.TNMain.main(TNMain.java:89)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.apache.tools.ant.taskdefs.ExecuteJava.run(ExecuteJava.java:202)
at org.apache.tools.ant.taskdefs.ExecuteJava.execute(ExecuteJava.java:134)
at org.apache.tools.ant.taskdefs.Java.run(Java.java:710)
at org.apache.tools.ant.taskdefs.Java.executeJava(Java.java:178)
at org.apache.tools.ant.taskdefs.Java.execute(Java.java:84)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:275)
at org.apache.tools.ant.Task.perform(Task.java:364)
at org.apache.tools.ant.Target.execute(Target.java:341)
at org.apache.tools.ant.Target.performTasks(Target.java:369)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1216)
at org.apache.tools.ant.Project.executeTarget(Project.java:1185)
at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:40)
at org.apache.tools.ant.Project.executeTargets(Project.java:1068)
at org.apache.tools.ant.module.bridge.impl.BridgeImpl.run(BridgeImpl.java:240)
at org.apache.tools.ant.module.run.TargetExecutor.run(TargetExecutor.java:293)
at org.netbeans.core.execution.RunClassThread.run(RunClassThread.java:131)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 28, 2007 4:43 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
http://www.hibernate.org/hib_docs/search/reference/en/html_single/#search-configuration-event

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 29, 2007 12:50 pm 
Newbie

Joined: Wed Mar 28, 2007 2:51 pm
Posts: 16
Hi.

Thanks for the link. I know less about JMS than I do about lucene, but will read this thoroughly.

Darren


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 29, 2007 1:02 pm 
Newbie

Joined: Wed Mar 28, 2007 2:51 pm
Posts: 16
I set this property

<property name="hibernate.search.autoregister_listeners">false</property>

in the hibernate config file to disable it and the exception still occurs.

But then I realized, I use explicit hibernate annotations to index certain fields and thus do not need this automatic indexing.

How can I get around the exception in this case?


thanks,
Darren


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 29, 2007 1:46 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
If you want to use Hibernate Search, you must have the event registered, the easy way is to let the default (no property, no explicit event listener) do the job.

_________________
Emmanuel


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 8 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.