elasticsearch,hibernate-search,Java,Hibernate,elasticsearch,Hibernate Search" /> elasticsearch,hibernate-search,Java,Hibernate,elasticsearch,Hibernate Search" />

“线程中的异常”;“主要”;java.lang.IllegalArgumentException:java.lang.Object不是索引实体或索引实体的子类

“线程中的异常”;“主要”;java.lang.IllegalArgumentException:java.lang.Object不是索引实体或索引实体的子类,java,hibernate,elasticsearch,hibernate-search,Java,Hibernate,elasticsearch,Hibernate Search,我正在尝试为ElasticSearch集成配置HibernateSearch。 我的oracle数据库中有Product表。从该表中,我尝试根据产品名称进行搜索 为此,我尝试将HibernateSearch(ElasticSearch)与oracle数据库集成在一起 我从HibernateSearch获取以下错误: 我正在使用Oracle数据库,并在pom.xml文件中添加了所需的依赖项 Exception in thread "main" java.lang.IllegalArgumentEx

我正在尝试为ElasticSearch集成配置HibernateSearch。 我的oracle数据库中有
Product
表。从该表中,我尝试根据产品名称进行搜索

为此,我尝试将HibernateSearch(ElasticSearch)与oracle数据库集成在一起

我从HibernateSearch获取以下错误:

我正在使用Oracle数据库,并在pom.xml文件中添加了所需的依赖项

Exception in thread "main" java.lang.IllegalArgumentException: java.lang.Object is not an indexed entity or a subclass of an indexed entity
at org.hibernate.search.batchindexing.impl.MassIndexerImpl.toRootEntities(MassIndexerImpl.java:87)
at org.hibernate.search.batchindexing.impl.MassIndexerImpl.<init>(MassIndexerImpl.java:63)
at org.hibernate.search.batchindexing.impl.DefaultMassIndexerFactory.createMassIndexer(DefaultMassIndexerFactory.java:33)
at org.hibernate.search.impl.FullTextSessionImpl.createIndexer(FullTextSessionImpl.java:175)
at com.test.webservice.elasticsearch.App.doIndex(App.java:36)
at com.test.webservice.elasticsearch.App.main(App.java:109)
App.java

public class App 
{

    private static void doIndex() throws InterruptedException {
        Session session = HibernateUtil.getSession();

        FullTextSession fullTextSession = Search.getFullTextSession(session);
        fullTextSession.createIndexer().startAndWait();   // Error occuring on this line

        fullTextSession.close();
    }

    private static List<Product> search(String queryString) {
        Session session = HibernateUtil.getSession();
        FullTextSession fullTextSession = Search.getFullTextSession(session);

        QueryBuilder queryBuilder = fullTextSession.getSearchFactory().buildQueryBuilder().forEntity(Product.class).get();
        org.apache.lucene.search.Query luceneQuery = queryBuilder.keyword().onFields("name").matching(queryString).createQuery();

        // wrap Lucene query in a javax.persistence.Query
        org.hibernate.Query fullTextQuery = fullTextSession.createFullTextQuery(luceneQuery, Product.class);

        List<Product> productList = fullTextQuery.list();

        fullTextSession.close();

        return productList;
    }

    private static void displayContactTableData() {
        Session session = null;
        PropertiesFile propertiesFile= PropertiesFile.getInstance();
        String driverClass = propertiesFile.extractPropertiesFile().getProperty("hibernate.connection.driver_class");
        String connectionURL = propertiesFile.extractPropertiesFile().getProperty("hibernate.connection.url");
        String userName = propertiesFile.extractPropertiesFile().getProperty("hibernate.connection.username");
        String password = propertiesFile.extractPropertiesFile().getProperty("hibernate.connection.password");
        String dialect = propertiesFile.extractPropertiesFile().getProperty("hibernate.dialect");
        String showSQL = propertiesFile.extractPropertiesFile().getProperty("hibernate.show_sql");

        try {
            //session = HibernateUtil.getSession();

            // Fetching saved data
            String hql = "from Product"; 
            @SuppressWarnings("unchecked")

             Configuration cfg=new Configuration()
            .setProperty("hibernate.connection.driver_class", driverClass)
            .setProperty("hibernate.connection.url", connectionURL)
            .setProperty("hibernate.connection.username", userName)
            .setProperty("hibernate.connection.password", password)
            .setProperty("hibernate.dialect", dialect)
            .setProperty("hibernate.show_sql", showSQL)
            .addAnnotatedClass(com.test.webservice.model.Product.class);

             SessionFactory factory=cfg.buildSessionFactory();  
             session=factory.openSession();  
             Transaction t=session.beginTransaction(); 

            List<Product> productList = session.createQuery(hql).list();

            for (Product product : productList) {
                System.out.println("Product Name --->"+product.getName());
            }

        } catch(HibernateException exception){
             System.out.println("Problem creating session factory");
             exception.printStackTrace();
        }finally{
            if(session != null) {
                session.close();
            }
        }
    }

    public static void main(String[] args) throws InterruptedException {
        System.out.println("\n\n******Data stored in Contact table******\n");
        displayContactTableData();

        // Create an initial Lucene index for the data already present in the database
        doIndex();   // Error occuring on this line

        Scanner scanner = new Scanner(System.in);
        String consoleInput = null;

        while (true) {
            // Prompt the user to enter query string
            System.out.println("\n\nEnter search key (To exit type 'X')");      
            System.out.println();
            consoleInput = scanner.nextLine();

            if("X".equalsIgnoreCase(consoleInput)) {
                System.out.println("End");
                System.exit(0);
            }   

            List<Product> result = search(consoleInput);            
            System.out.println("\n\n>>>>>>Record found for '" + consoleInput + "'");

            for (Product product : result) {
                System.out.println(product);
            }               
        }           
    }
}

错误消息错误,应该是“java.lang.Object不是索引实体或索引实体的超类”。我想,我们会尽快修复错误消息

关于您的问题,此异常意味着
对象
及其任何子类都没有索引。简而言之,没有任何索引类

我可以看到您的
产品
类用
@索引
注释,因此这可能意味着在
HibernateUtil
中如何启动Hibernate ORM存在问题

一个简单的事实是,您注释了您的行
session=HibernateUtil.getSession()displayContactTableData()
中的code>让我觉得你已经知道了这一点


您应该查看以确保正确启动Hibernate ORM。

错误消息应该是“java.lang.Object不是索引实体或索引实体的超类”。我想,我们会尽快修复错误消息

关于您的问题,此异常意味着
对象
及其任何子类都没有索引。简而言之,没有任何索引类

我可以看到您的
产品
类用
@索引
注释,因此这可能意味着在
HibernateUtil
中如何启动Hibernate ORM存在问题

一个简单的事实是,您注释了您的行
session=HibernateUtil.getSession()displayContactTableData()
中的code>让我觉得你已经知道了这一点


您应该查看以确保正确启动Hibernate ORM。

我也遇到了同样的问题,我将导入从
import org.springframework.stereotype.index
导入org.hibernate.search.annotations.index成功了

我也遇到了同样的问题,我将导入内容从
import org.springframework.stereotype.index更改为
import
导入org.hibernate.search.annotations.index成功了

这个错误仍然存在。不确定如何解决这个问题以及它是如何发生的。?这个错误仍然存在。不确定如何解决这个问题以及它是如何发生的。??
public class App 
{

    private static void doIndex() throws InterruptedException {
        Session session = HibernateUtil.getSession();

        FullTextSession fullTextSession = Search.getFullTextSession(session);
        fullTextSession.createIndexer().startAndWait();   // Error occuring on this line

        fullTextSession.close();
    }

    private static List<Product> search(String queryString) {
        Session session = HibernateUtil.getSession();
        FullTextSession fullTextSession = Search.getFullTextSession(session);

        QueryBuilder queryBuilder = fullTextSession.getSearchFactory().buildQueryBuilder().forEntity(Product.class).get();
        org.apache.lucene.search.Query luceneQuery = queryBuilder.keyword().onFields("name").matching(queryString).createQuery();

        // wrap Lucene query in a javax.persistence.Query
        org.hibernate.Query fullTextQuery = fullTextSession.createFullTextQuery(luceneQuery, Product.class);

        List<Product> productList = fullTextQuery.list();

        fullTextSession.close();

        return productList;
    }

    private static void displayContactTableData() {
        Session session = null;
        PropertiesFile propertiesFile= PropertiesFile.getInstance();
        String driverClass = propertiesFile.extractPropertiesFile().getProperty("hibernate.connection.driver_class");
        String connectionURL = propertiesFile.extractPropertiesFile().getProperty("hibernate.connection.url");
        String userName = propertiesFile.extractPropertiesFile().getProperty("hibernate.connection.username");
        String password = propertiesFile.extractPropertiesFile().getProperty("hibernate.connection.password");
        String dialect = propertiesFile.extractPropertiesFile().getProperty("hibernate.dialect");
        String showSQL = propertiesFile.extractPropertiesFile().getProperty("hibernate.show_sql");

        try {
            //session = HibernateUtil.getSession();

            // Fetching saved data
            String hql = "from Product"; 
            @SuppressWarnings("unchecked")

             Configuration cfg=new Configuration()
            .setProperty("hibernate.connection.driver_class", driverClass)
            .setProperty("hibernate.connection.url", connectionURL)
            .setProperty("hibernate.connection.username", userName)
            .setProperty("hibernate.connection.password", password)
            .setProperty("hibernate.dialect", dialect)
            .setProperty("hibernate.show_sql", showSQL)
            .addAnnotatedClass(com.test.webservice.model.Product.class);

             SessionFactory factory=cfg.buildSessionFactory();  
             session=factory.openSession();  
             Transaction t=session.beginTransaction(); 

            List<Product> productList = session.createQuery(hql).list();

            for (Product product : productList) {
                System.out.println("Product Name --->"+product.getName());
            }

        } catch(HibernateException exception){
             System.out.println("Problem creating session factory");
             exception.printStackTrace();
        }finally{
            if(session != null) {
                session.close();
            }
        }
    }

    public static void main(String[] args) throws InterruptedException {
        System.out.println("\n\n******Data stored in Contact table******\n");
        displayContactTableData();

        // Create an initial Lucene index for the data already present in the database
        doIndex();   // Error occuring on this line

        Scanner scanner = new Scanner(System.in);
        String consoleInput = null;

        while (true) {
            // Prompt the user to enter query string
            System.out.println("\n\nEnter search key (To exit type 'X')");      
            System.out.println();
            consoleInput = scanner.nextLine();

            if("X".equalsIgnoreCase(consoleInput)) {
                System.out.println("End");
                System.exit(0);
            }   

            List<Product> result = search(consoleInput);            
            System.out.println("\n\n>>>>>>Record found for '" + consoleInput + "'");

            for (Product product : result) {
                System.out.println(product);
            }               
        }           
    }
}
<hibernate-configuration>
    <session-factory>

        <property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
        <property name="hibernate.connection.url">jdbc:oracle:thin:@localhost:1521:xe</property>
        <property name="hibernate.connection.username">vb</property>
        <property name="hibernate.connection.password">123456</property>
        <property name="hibernate.dialect">org.hibernate.dialect.OracleDialect</property>
        <property name="show_sql">false</property>
        <property name="format_sql">true</property>

        <property name="hibernate.hbm2ddl.auto">update</property>

        <property name="hibernate.search.default.directory_provider">filesystem</property>
        <property name="hibernate.search.default.indexBase">C:\lucene\indexes</property>

        <mapping class="com.test.webservice.model.Product" />

    </session-factory>
</hibernate-configuration>
@Entity
@Indexed
@Table(name = "PRODUCT")
public class Product {

    private String name;
    private long id;

    @Field(index = Index.YES, analyze = Analyze.YES, store = Store.NO)
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }


    public void setId(long id) {
        this.id = id;
    }

    @Id
    public long getId() {
        return id;
    }

}