首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在JBoss数据网格中使用hibernate-search?

如何在JBoss数据网格中使用hibernate-search?
EN

Stack Overflow用户
提问于 2013-10-31 00:07:01
回答 1查看 449关注 0票数 1

我需要使用JBoss Datagrid来停止一些文档并使其可搜索。所以,我正在考虑使用Hibernate搜索,它已经是JBoss的一部分了。但现在我被卡住了。下面是我用JUnit生成的一个简单代码。

代码语言:javascript
复制
@Test
public void testName() throws Exception {
    Cache<Object, Object> c = new DefaultCacheManager().getCache();
    c.put("id", new ProductDG("ean", "desc", newArrayList("image1")));

    ProductDG product = (ProductDG) c.get("id");
    assertTrue(product.getEAN().equals("ean"));

    SessionFactory factory = new AnnotationConfiguration().buildSessionFactory();
    Session session = factory.openSession();

    FullTextSession fts = getFullTextSession(session);
    fts.index(product);

}


@Indexed(index="Product")
class ProductDG {
    private String EAN;
    private String description;

    private List<String> images;

    ProductDG(String EAN, String description, List<String> images) {
        this.EAN = EAN;
        this.description = description;
        this.images = images;
    }

    String getEAN() {
        return EAN;
    }

    String getDescription() {
        return description;
    }

    List<String> getImages() {
        return images;
    }
}

但是我得到了像这样的错误。

代码语言:javascript
复制
org.hibernate.HibernateException: Connection cannot be null when 'hibernate.dialect' not set
    at org.hibernate.service.jdbc.dialect.internal.DialectFactoryImpl.determineDialect(DialectFactoryImpl.java:97)
    at org.hibernate.service.jdbc.dialect.internal.DialectFactoryImpl.buildDialect(DialectFactoryImpl.java:67)
    at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:174)
    at org.hibernate.service.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:75)
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:159)
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:131)
    at org.hibernate.cfg.Configuration.buildTypeRegistrations(Configuration.java:1797)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1755)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1840)
    at com.tesco.adapters.JBossDataGrid.testName(JBossDataGrid.java:27)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:157)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:77)
    at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:195)
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:63)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)

我想我没有可以连接的数据库。这到底是如何工作的呢?我被告知我必须使用JBoss数据网格。我知道https://docs.jboss.org/hibernate/ogm/3.0/reference/en-US/html_single/,但它太新了,几个月前才出来。这完全可以做到吗?

EN

回答 1

Stack Overflow用户

发布于 2013-11-03 00:12:26

您说得对,JBoss数据网格使用Hibernate搜索,但它只用于索引和查询定义:您不需要通过“传统的”Hibernate会话使用它。

  • 您不需要启动Hibernate SessionFactory

  • You甚至不需要类路径上的Hibernate ORM

  • 您可以使用Hibernate Search

中的批注

要创建受您的域启发的示例,只需在configuration of the Cache中启用索引即可。

代码语言:javascript
复制
@Test
public void testName() throws Exception {
   Cache<Object, Object> c = new DefaultCacheManager("configuration-file.xml").getCache();
   c.put("id", new ProductDG("ean", "desc", newArrayList("image1")));
   //at this point your Product is already indexed (assuming you don't use transactions)

   //Using the MatchAllDocsQuery we'll get a list of all instances:
   CacheQuery query = searchManager.getQuery(new MatchAllDocsQuery(), ProductDG.class);

   // Execute Query
   List objectList = query.list();

   for (Object prod : objectList)
      System.out.println(prod);

}

最后一个问题是关于Hibernate OGM的。是的,也可以这样做,但您可能想要阅读版本4的文档:

https://docs.jboss.org/hibernate/ogm/4.0/reference/en-US/html_single/

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19688026

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档