hibernate-search MassIndexer ERROR

时间:2016-07-05 15:05:48

标签: elasticsearch hibernate-search

我想用hibernate-search-orm项目中的MassIndexer系统重新索引elasticsearch索引中的实体。

它可能很棒;)但它告诉我一些例外情况。

但是如下所示,示例是基本的:

  1. 实体:

    @Entity
    @Table(name = "STUDENT")
    @Indexed
    @ProvidedId (bridge = @FieldBridge(impl = StudentFieldBridge.class))
    public class StudentEntity {
    
        @EmbeddedId
        private RegistrationId regid;
    
        @Field
        private String name;
        ...
    }
    
  2. registrationId

    @Embeddable
    public class RegistrationId implements Serializable{
    
        @Column(name = "STUDENT_ID")
        private int studentId;
    
        @Column(name = "DEPARTMENT")
        private String department;
        ...
    }
    
  3. 学生场桥:

    public class StudentFieldBridge implements TwoWayStringBridge {
    
        @Override
        public Object stringToObject(String stringValue) {
            String[] split = stringValue.split("_");
            RegistrationId ret = new RegistrationId();
            ret.setDepartment(split[0]);
            ret.setStudentId(Integer.parseInt(split[1]));
            return ret;
        }
    
        @Override
        public String objectToString(Object object) {
            RegistrationId id = (RegistrationId) object;
            return id.getDepartment() + "_" + id.getStudentId();
        }
    }
    
  4. 群众指数化

    @Test
    public void massIndexation() throws InterruptedException {
        EntityManager em = Persistence.createEntityManagerFactory("studentPu").createEntityManager();
        org.hibernate.Session hibernateSession = (Session)em.getDelegate();
        FullTextSession fullTextSession = Search.getFullTextSession(hibernateSession);
        fullTextSession.createIndexer().startAndWait();
    }   
    
  5. 最后是错误:

    ERROR: HSEARCH000058: HSEARCH000212: An exception occurred while the MassIndexer was transforming identifiers to Lucene Documents
    java.lang.NullPointerException
    at org.hibernate.loader.criteria.CriteriaQueryTranslator.getEntityName(CriteriaQueryTranslator.java:626)
    at org.hibernate.loader.criteria.CriteriaQueryTranslator.getColumns(CriteriaQueryTranslator.java:509)
    at org.hibernate.loader.criteria.CriteriaQueryTranslator.findColumns(CriteriaQueryTranslator.java:525)
    at org.hibernate.criterion.InExpression.toSqlString(InExpression.java:43)
    at org.hibernate.loader.criteria.CriteriaQueryTranslator.getWhereCondition(CriteriaQueryTranslator.java:400)
    at org.hibernate.loader.criteria.CriteriaJoinWalker.<init>(CriteriaJoinWalker.java:106)
    at org.hibernate.loader.criteria.CriteriaJoinWalker.<init>(CriteriaJoinWalker.java:75)
    at org.hibernate.loader.criteria.CriteriaLoader.<init>(CriteriaLoader.java:80)
    at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1760)
    at org.hibernate.internal.CriteriaImpl.list(CriteriaImpl.java:363)
    at org.hibernate.search.batchindexing.impl.IdentifierConsumerDocumentProducer.loadList(IdentifierConsumerDocumentProducer.java:175)
    at org.hibernate.search.batchindexing.impl.IdentifierConsumerDocumentProducer.loadAllFromQueue(IdentifierConsumerDocumentProducer.java:140)
    at org.hibernate.search.batchindexing.impl.IdentifierConsumerDocumentProducer.run(IdentifierConsumerDocumentProducer.java:117)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:744)
    
  6. java项目依赖项是:

    testCompile group: 'org.hibernate', name: 'hibernate-entitymanager', version: '5.0.8.Final'
    testCompile group: 'org.hibernate', name: 'hibernate-search-orm', version: '5.6.0.Alpha3'
    testCompile group: 'org.hibernate', name: 'hibernate-search-backend-elasticsearch', version: '5.6.0.Alpha3'
    

    感谢项目团队的工作!

1 个答案:

答案 0 :(得分:0)

这应该有效:

@Entity
@Table(name = "STUDENT")
@Indexed
public class StudentEntity {

    @EmbeddedId
    @DocumentId
    @FieldBridge(impl = StudentFieldBridge.class)
    private RegistrationId regid;

    @Field
    private String name;

问题是由@ProvidedId注释引起的,它与MassIndexer不兼容:它适用于与Hibernate Search集成的其他框架,以直接提供外部分配的ID。 如果id是从外部分配的,则MassIndexer无法猜测它们,因此不应将它们一起使用。

我将尝试澄清ProvidedId关于此的文档,或者可能弃用/删除注释,因为我没想到它会导致这样一个令人困惑的错误。谢谢你的举报!