Hibernate FullTextSearch Exception at SessionInitialize

僤鯓⒐⒋嵵緔 提交于 2019-12-13 05:27:12

问题


I am trying to create fulltext indexes and take specific search result as list with Hibernate. I can not pass beyond session initialization.

Here is my code:

This is HibernateUtil Class:

public class HibernateUtil {

private static final SessionFactory sessionFactory;

static {
    try {
        // Create the SessionFactory from standard (hibernate.cfg.xml) 
        // config file.
        sessionFactory = new AnnotationConfiguration().configure().buildSessionFactory();
    } catch (Throwable ex) {
        // Log the exception. 
        System.err.println("Initial SessionFactory creation failed." + ex);
        throw new ExceptionInInitializerError(ex);
    }
}

public static SessionFactory getSessionFactory() {
    return sessionFactory;
}
}

This is the code I start FullTextSession:

try {
        fullTextSession = Search.getFullTextSession(HibernateUtil.getSessionFactory().getCurrentSession());
        fullTextSession.createIndexer().startAndWait();
    } catch (InterruptedException ex) {
        Logger.getLogger(SatisYonetimiEkrani.class.getName()).log(Level.SEVERE, null, ex);
    }

And this is the function where I want to make fulltext search:

private void aramaYap() {
    QueryBuilder productQb = fullTextSession.getSearchFactory().buildQueryBuilder().forEntity(Satislar.class).get();
    Query fullTextQuery = (Query) productQb.keyword().onField("musteriadi").matching("Ramazan").createQuery();

    List<Satislar> satis = fullTextQuery.list();

    for (int i = 0; i < satis.size(); i++) {
        System.out.println(satis.get(i).getMusteriadi());
    }
}

I think I may have problems with my jar files. Here is list of jar files:


回答1:


Your versions of Hibernate ORM (4.3) and Hibernate Search (5.5) don't match. Hibernate Search 5.5 is meant to be used with ORM 5.x (5.0.6 is the latest at this time).

Also you have Hibernate ORM and EclipseLink on your classpath, which at least for the spec packages (javax.persistence.*) gives you duplicated packages. Assuming you want to work with Hibernate Search, you should remote the EclipseLink JARs.

On a more general note, you will greatly benefit from using a dependency management tool such as Maven, Gradle or Ant+Ivy.



来源:https://stackoverflow.com/questions/34404406/hibernate-fulltextsearch-exception-at-sessioninitialize

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!