我正在尝试使用Hibernate创建全文索引并将特定搜索结果作为列表。 我不能超越会话初始化。
这是我的代码:
这是HibernateUtil类:
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;
}
}
这是我启动FullTextSession的代码:
try {
fullTextSession = Search.getFullTextSession(HibernateUtil.getSessionFactory().getCurrentSession());
fullTextSession.createIndexer().startAndWait();
} catch (InterruptedException ex) {
Logger.getLogger(SatisYonetimiEkrani.class.getName()).log(Level.SEVERE, null, ex);
}
这是我想要进行全文搜索的功能:
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());
}
}
我想我的jar文件可能有问题。这是jar文件列表:
答案 0 :(得分:0)
您的Hibernate ORM(4.3)和Hibernate Search(5.5)版本不匹配。 Hibernate Search 5.5适用于ORM 5.x(5.0.6是目前最新版本)。
此外,您的类路径上还有Hibernate ORM 和 EclipseLink,至少对于规范包(javax.persistence。*)为您提供了重复的包。假设你想使用Hibernate Search,你应该远程使用EclipseLink JAR。
更一般地说,使用依赖管理工具(如Maven,Gradle或Ant + Ivy)将大大受益。