Hibernate Books

All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 13 posts ] 
Author Message
 Post subject: HSEARCH000222: The SearchFactory was not initialized
PostPosted: Thu Jan 07, 2016 9:37 am 
Newbie

Joined: Fri Nov 13, 2015 12:19 am
Posts: 13
Hi,

I tried Integrating Hibernate Search-5.5.2 with Hibernate ORM - 5.0.6 Version. SessionFactory is Created Successfully and on executing the below lines of code as mentioned in the Documentation, I Can see searchFactory and searchFactory of fullTextSession object is null.

Code:
FullTextSession fullTextSession = Search.getFullTextSession(session); 
fullTextSession.createIndexer().startAndWait();


On Further debugging it with the source code, this.extendedIntegrator is coming as Null in class SearchFactoryReference

PFB, is the stack trace.
Code:
org.hibernate.search.exception.SearchException: HSEARCH000222: The SearchFactory was not initialized
   at org.hibernate.search.hcore.impl.SearchFactoryReference.getSearchIntegrator(SearchFactoryReference.java:35)
   at org.hibernate.search.hcore.util.impl.ContextHelper.getSearchintegratorBySFI(ContextHelper.java:44)
   at org.hibernate.search.hcore.util.impl.ContextHelper.getSearchintegratorBySessionImplementor(ContextHelper.java:37)
   at org.hibernate.search.hcore.util.impl.ContextHelper.getSearchintegrator(ContextHelper.java:33)
   at org.hibernate.search.impl.FullTextSessionImpl.getSearchIntegrator(FullTextSessionImpl.java:179)
   at org.hibernate.search.impl.FullTextSessionImpl.createMassIndexerFactory(FullTextSessionImpl.java:191)
   at org.hibernate.search.impl.FullTextSessionImpl.createIndexer(FullTextSessionImpl.java:161)


Could any one please help me in resolving this. I feel i am missing something here.

SessionFactory Creation:

Code:
BootstrapServiceRegistry bootstrapServiceRegistry = new BootstrapServiceRegistryBuilder().build();
StandardServiceRegistry standardRegistry = new        StandardServiceRegistryBuilder(bootstrapServiceRegistry).configure(configFile).build();
Metadata metadata = new MetadataSources( standardRegistry).getMetadataBuilder().build();
sessionFactory = metadata.getSessionFactoryBuilder().build();


List of Jars in my Classpath:
Code:
antlr-2.7.7.jar;
codemodel-2.6.jar;
commons-configuration-1.10.jar;
commons-io-2.4.jar;
commons-logging-1.2.jar;
dom4j-1.6.1.jar;
flexjson-3.3.jar;
hibernate-commons-annotations-5.0.1.Final.jar;
hibernate-core-5.0.6.Final.jar;
hibernate-jpa-2.1-api-1.0.0.Final.jar;
hibernate-search-engine-5.5.2.Final.jar;
hibernate-search-orm-5.5.2.Final.jar;
jackson-annotations-2.6.3.jar;
jackson-core-2.6.3.jar;
jackson-databind-2.6.3.jar;
jackson-jaxrs-base-2.6.3.jar;
jackson-jaxrs-json-provider-2.6.3.jar;
jackson-module-afterburner-2.6.3.jar;
jandex-1.1.0.Final.jar;
jandex-2.0.0.Final.jar;
javassist-3.18.1-GA.jar;
jboss-logging-3.3.0.Final.jar;
jboss-logging-annotations-1.2.0.Final.jar;
jboss-transaction-api_1.2_spec-1.0.0.Final.jar;
logback-classic-1.1.3.jar;
logback-core-1.1.3.jar;
lucene-core-5.3.1.jar;
ojdbc6.jar;
slf4j-api-1.7.10.jar;
xml-apis-1.3.03.jar;
yamlbeans-1.09.jar;



Thank you,
Domnic Nadar.


Top
 Profile  
 
 Post subject: Re: HSEARCH000222: The SearchFactory was not initialized
PostPosted: Tue Jan 12, 2016 7:08 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
Hi,
I'm surprised, I don't see any obvious mistake. The integration between Hibernate ORM and Hibernate Search works using a service discovery mechanism: Hibernate ORM needs to be able to "see" the Hibernate Search jars. So my question: are you running this in some container?

Your dependencies seem correct as well, except I'm not sure why you have jandex-1.1.0.Final.jar: these Hibernate versions only require Jandex 2.

_________________
Sanne
http://in.relation.to/


Top
 Profile  
 
 Post subject: Re: HSEARCH000222: The SearchFactory was not initialized
PostPosted: Tue Jan 12, 2016 1:40 pm 
Newbie

Joined: Fri Nov 13, 2015 12:19 am
Posts: 13
Hi Sanne,

Thanks for your reply. Yes I am using Apache TOMEE application server with apache CFX inbuilt in it.

I was verifying hibernate search with prior releases too. May be I missed to remove Jandex 1.1 version.

Let me know if you need any more information.

Thanks again.


Top
 Profile  
 
 Post subject: Re: HSEARCH000222: The SearchFactory was not initialized
PostPosted: Wed Jan 13, 2016 9:33 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
Hi,

my guess is the problem lies in how the dependencies are being loaded by the container. It might also relate with how you organize the dependencies: are they all part of your app's deployment classpath, or are you adding some to the lib directories of the container?

I haven't used TomEE before, but I would like to reproduce this issue as it would be nice to have it "just work" on that container too.

Would you be able to share a very simple sample project so that I can see exactly how it is packaged and run on TomEE?

Feel free to create a JIRA for this and provide attachments there. Alternatively if you feel up to it I would accept a pull request to add Arquillian integration tests using TomEE: even failing tests would be helpful of course.

_________________
Sanne
http://in.relation.to/


Top
 Profile  
 
 Post subject: Re: HSEARCH000222: The SearchFactory was not initialized
PostPosted: Thu Jan 14, 2016 5:43 am 
Newbie

Joined: Fri Nov 13, 2015 12:19 am
Posts: 13
Hi Sanne,

As you mentioned about Application Server, i thought of Trying it with simple java Project and I am facing the same issue. :(

Exception occurs at fullTextSession.createIndexer().startAndWait(); Could you please help and let me know if i am missing something?

Properties added along with ORM Hibernate configurations.

<property name="hibernate.search.default.directory_provider">filesystem</property>
<property name="hibernate.search.default.indexBase">D:\\Domnic\\indexLucene</property>

I am Using JDK - 1.7.0_25




List of Jars in my classpath.
Code:
antlr-2.7.7.jar;
dom4j-1.6.1.jar;
hibernate-commons-annotations-5.0.1.Final.jar;
hibernate-core-5.0.6.Final.jar;
hibernate-jpa-2.1-api-1.0.0.Final.jar;
hibernate-search-engine-5.5.2.Final;
hibernate-search-orm-5.5.2.Final;
jandex-2.0.0.Final.jar;
javassist-3.18.1-GA.jar;
jboss-annotations-api_1.2_spec-1.0.0.Final.jar;
jboss-jms-api_2.0_spec-1.0.0.Final.jar;
jboss-logging-3.3.0.Final.jar;
jboss-transaction-api_1.2_spec-1.0.0.Final.jar;
lucene-core-5.3.1.jar;
xml-apis-1.3.03.jar;
ojdbc6.jar;


Sample Code:
POJO Class - Book.java
Code:
package com.wom.hib.search;

import javax.persistence.GeneratedValue;
import javax.persistence.Id;

import org.hibernate.search.annotations.Field;
import org.hibernate.search.annotations.Indexed;

@javax.persistence.Entity
@Indexed
public class Book {


   @Id
   @GeneratedValue
   private Integer id;
   @Field
   private String title;
   @Field
   private String subtitle;

   public Integer getId() {
      return id;
   }
   public void setId(Integer id) {
      this.id = id;
   }
   public String getTitle() {
      return title;
   }
   public void setTitle(String title) {
      this.title = title;
   }
   public String getSubtitle() {
      return subtitle;
   }
   public void setSubtitle(String subtitle) {
      this.subtitle = subtitle;
   }


}


Hibernate Util Class
Code:
package com.wom.hib.search;

import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

public class HibernateUtil {

   private static SessionFactory sessionFactory;

   public static  SessionFactory buildSessionFactory() {
      try {

         Configuration configuration = new Configuration();
         configuration.configure();
         sessionFactory = configuration.buildSessionFactory();
         return sessionFactory;


      }
      catch (Throwable ex) {
         // Make sure you log the exception, as it might be swallowed
         System.err.println("Initial SessionFactory creation failed." + ex);
         throw new ExceptionInInitializerError(ex);
      }
   }

   public static SessionFactory getSessionFactory() {
      return sessionFactory;
   }

   public static void shutdown() {
      getSessionFactory().close();
   }
}


Main Test Class
Code:
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.search.FullTextSession;
import org.hibernate.search.Search;

public class TestHibSearch {

   public static void main(String[] args) throws InterruptedException {

      HibernateUtil.buildSessionFactory();
      Session session = HibernateUtil.getSessionFactory().openSession();
      Transaction tx = session.beginTransaction();
      
      /*Book book1 = new Book();
      book1.setId(123456);
      book1.setSubtitle("SubTitle");
      book1.setTitle("Here we go!!");
      
      session.save(book1);
      tx.commit();*/
      
      
      FullTextSession fullTextSession = Search.getFullTextSession(session);
      fullTextSession.createIndexer().startAndWait();
      
      session.close();
      HibernateUtil.shutdown();
   }
}



Thank you,
Domnic Nadar.


Top
 Profile  
 
 Post subject: Re: HSEARCH000222: The SearchFactory was not initialized
PostPosted: Sat Jan 16, 2016 8:12 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
Hi,
I'm surprised, it seems you are not using a dependency management tool?

I'm not sure which of the missing dependencies is causing the specific issue, but comparing your dependencies with a demo project I have there are several missing: hibernate-entitymanager, lucene-facet, lucene-queries, lucene-analyzers-common, lucene-misc.

There is a minimal example project here:
- https://github.com/Sanne/tweets-cli-demo

I hope that helps?
I will try to setup your project too, it's interesting that you use the Hibernate native API and seem to want to avoid the hibernate-entitymanager.. I'm not sure if that was tested so I will now, as that should work fine but I'm not sure. the Hibernate ORM team has been talking of including hibernate-entitymanager in -core, I'm wondering if it's not longer optional already (that wouldn't have been intentional yet).

_________________
Sanne
http://in.relation.to/


Top
 Profile  
 
 Post subject: Re: HSEARCH000222: The SearchFactory was not initialized
PostPosted: Mon Jan 18, 2016 4:06 am 
Newbie

Joined: Fri Nov 13, 2015 12:19 am
Posts: 13
Hi Sanne,

I am not using any dependency Management tool for Hibernate Search. I had downloaded, hibernate-search-5.5.2.Final-dist package and added all the Required jars available in my classpath.
The Jars mentioned by you Lucene-facet, Lucene-queries and lucene-misc arent present in the package and lucene-analyzers-common is added under optional folder.

I downloaded these jars mentioned by you and had them in my classpath (Added hibernate-entityManager too). Still i am facing the same exception.

I checked your project, I see the project contains usage of EnityManager for Hibernate Search. Our entire application is build up on Native Hibernate APIs and wanted to proceed with Hibernate APIs and sessions. Could you please help and see executing from your side whether it works with Hibernate Native APIs. I hope it works and i am missing something.

Thank you,
Domnic Nadar.


Top
 Profile  
 
 Post subject: Re: HSEARCH000222: The SearchFactory was not initialized
PostPosted: Tue Jan 19, 2016 10:22 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
Hi,
you are right, using the Hibernate native APIs could introduce some differences.

So I patched my little demo to avoid using JPA, but again it seems like it's all working fine.

I don't have more ideas on why it might not be working for you, but I hope you could checkout my trivial demo and see if it helps?

It is in the same location as mentioned before, but in a dedicated branch named "HibernateNative".

https://github.com/Sanne/tweets-cli-dem ... nateNative

_________________
Sanne
http://in.relation.to/


Top
 Profile  
 
 Post subject: Re: HSEARCH000222: The SearchFactory was not initialized
PostPosted: Thu Jan 21, 2016 12:13 pm 
Newbie

Joined: Fri Nov 13, 2015 12:19 am
Posts: 13
Hi Sanne,

The Same project which you shared is working for me and i am able to run the ServiceTest and no exception occured while creating
Hibernate Search Factory. :)

On Running the Same i could see few errors though, not sure is there anything i need to modify in tweet.class.

Code:
FullTextQuery droolsQuery = service.messagesMentioning( "Drools" );
Assert.assertEquals( 2, droolsQuery.getResultSize() );
List list = droolsQuery.list();


droolsQuery.getResultSize() gives me result size as 2 but the List is Empty ([]). Also on List call i can see SQL Queries are fired in the log.
Hibernate: select this_.id as id1_0_0_, this_.message as message2_0_0_, this_.sender as sender3_0_0_, this_.timestamp as timestam4_0_0_ from Tweet this_ where (this_.id in (?, ?))

Since the List is returned as empty, it failed in line no 82

Code:
               FullTextQuery infinispanQuery = service.messagesMentioning( "infinispan" );
         Assert.assertEquals( 1, infinispanQuery.getResultSize() );
         Tweet infinispanRelatedTweet = (Tweet) infinispanQuery.list().get( 0 );


PFB, is the Error Got.

Code:
java.lang.IndexOutOfBoundsException: Index: 0
   at java.util.Collections$EmptyList.get(Unknown Source)
   at org.hibernate.search.demos.tweets.ServiceTest.testHibernateSearchUsingHibernateNativeAPIs(ServiceTest.java:82)


Could you please assist me on this?

Many thanks for the Help.

Thank you,
Domnic Nadar.


Top
 Profile  
 
 Post subject: Re: HSEARCH000222: The SearchFactory was not initialized
PostPosted: Thu Jan 21, 2016 12:48 pm 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
Did you make any change to it?
It should pass the tests as-is, and I see no reason for it to be depending on platforms or such. Unless you have some service running on the same ports as H2 (the testing in-memory database it's using)?

_________________
Sanne
http://in.relation.to/


Top
 Profile  
 
 Post subject: Re: HSEARCH000222: The SearchFactory was not initialized
PostPosted: Thu Jan 21, 2016 2:24 pm 
Newbie

Joined: Fri Nov 13, 2015 12:19 am
Posts: 13
Yes sanne, I loaded the project with dependency management tool and pointed it to MariaDB instead of h2. Also, the project didn't had hibernateUtil class..so I created one.

Also changed index directory from ram to filesystem and gave an index path. Index files are generated on that location by lucene.

Apart from that I didn't modify anything.


Top
 Profile  
 
 Post subject: Re: HSEARCH000222: The SearchFactory was not initialized
PostPosted: Fri Jan 22, 2016 11:46 am 
Newbie

Joined: Fri Nov 13, 2015 12:19 am
Posts: 13
Hi Sanne,

I tried running the sample Project you shared with h2 DB and it worked fine. :)
Later i tried pointing it to MariaDB with MySQL Dialet and it is giving me the count correctly but on retrieval it fails as i mentioned in the previous post.

Code:
java.lang.IndexOutOfBoundsException: Index: 0
   at java.util.Collections$EmptyList.get(Unknown Source)
   at org.hibernate.search.demos.tweets.ServiceTest.testHibernateSearchUsingHibernateNativeAPIs(ServiceTest.java:82)


Later i pointed it to my oracle DB and it worked fine.

I guess, MySql Dialet doesn't support entirely MariaDB as there is no Official talks in Hibernate portal. Could be better if it can work for MariaDB too.

Thanks so much Sanne, it really helped.

Thank you,
Domnic Nadar.


Top
 Profile  
 
 Post subject: Re: HSEARCH000222: The SearchFactory was not initialized
PostPosted: Mon Jan 25, 2016 1:30 pm 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
Hi Domnic,
MariaDB is supported as well and it should work fine.

My guess is that you had an index stored on disk from a previous experiment?
When testing and developing you might want to make sure to use an in-memory index, or to rebuild the index from scratch each time.

_________________
Sanne
http://in.relation.to/


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 13 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.