Hibernate NoSuchFieldError:INSTANCE

时间:2016-06-13 16:14:42

标签: spring hibernate jpa entitymanager hibernate-search

我正在尝试将Hibernate Search与Spring Data JPA集成,因此我编写了一个示例代码来测试它。

@PersistenceContext
EntityManager em;

@Override
@Transactional
public List<Place> findAll() {
    FullTextEntityManager fullTextSession = Search.getFullTextEntityManager(em);

    QueryBuilder builder = fullTextSession.getSearchFactory().buildQueryBuilder().forEntity(Place.class).get();

    double centerLatitude = 0d;
    double centerLongitude = 0d;
    org.apache.lucene.search.Query luceneQuery = builder
            .spatial()
            .within(100, Unit.KM)
            .ofLatitude(centerLatitude)
            .andLongitude(centerLongitude)
            .createQuery();

    javax.persistence.Query jpaQuery =
            fullTextSession.createFullTextQuery(luceneQuery, Place.class);

    em.close();
    return jpaQuery.getResultList();
}

我跟随堆栈跟踪得到了异常。

2016-06-13 17:34:30 INFO  LogHelper:31 - HHH000204: Processing PersistenceUnitInfo [
    name: default
    ...]
2016-06-13 17:34:30 INFO  Version:37 - HHH000412: Hibernate Core {5.0.6.Final}
2016-06-13 17:34:30 INFO  Environment:213 - HHH000206: hibernate.properties not found
2016-06-13 17:34:30 INFO  Environment:317 - HHH000021: Bytecode provider name : javassist
2016-06-13 17:34:30 INFO  Version:66 - HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
2016-06-13 17:34:31 INFO  Dialect:154 - HHH000400: Using dialect: org.hibernate.dialect.MySQLDialect
2016-06-13 17:34:31 INFO  Version:30 - HV000001: Hibernate Validator 5.2.4.Final
2016-06-13 17:34:31 INFO  Version:26 - HSEARCH000034: Hibernate Search 5.5.3.Final
2016-06-13 17:34:32 INFO  SchemaUpdate:105 - HHH000228: Running hbm2ddl schema update
2016-06-13 17:34:32 WARN  ConfigContext:346 - HSEARCH000075: Configuration setting hibernate.search.lucene_version was not specified: using LUCENE_CURRENT.
//...    

[localhost-startStop-1] WARN org.springframework.web.context.support.AnnotationConfigWebApplicationContext - Exception encountered during context initialization - cancelling refresh attempt
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in pl.project.api.config.RepositoryConfig: Invocation of init method failed; nested exception is java.lang.NoSuchFieldError: INSTANCE
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1578)
//...
Caused by: java.lang.NoSuchFieldError: INSTANCE
    at org.hibernate.search.store.impl.DefaultLockFactoryCreator.createLockFactory(DefaultLockFactoryCreator.java:60)
    at org.hibernate.search.store.impl.DirectoryProviderHelper.getLockFactory(DirectoryProviderHelper.java:134)
    at org.hibernate.search.store.impl.DirectoryProviderHelper.createFSIndex(DirectoryProviderHelper.java:124)
    at org.hibernate.search.store.impl.FSDirectoryProvider.initialize(FSDirectoryProvider.java:53)
    at org.hibernate.search.store.spi.BaseDirectoryProviderService.initialize(BaseDirectoryProviderService.java:64)
    at org.hibernate.search.store.spi.BaseDirectoryProviderService.create(BaseDirectoryProviderService.java:49)
    at org.hibernate.search.indexes.spi.DirectoryBasedIndexManager.createDirectoryProvider(DirectoryBasedIndexManager.java:230)
    at org.hibernate.search.indexes.spi.DirectoryBasedIndexManager.initialize(DirectoryBasedIndexManager.java:90)
    at org.hibernate.search.indexes.impl.IndexManagerHolder.createIndexManager(IndexManagerHolder.java:256)
    at org.hibernate.search.indexes.impl.IndexManagerHolder.createIndexManager(IndexManagerHolder.java:513)
    at org.hibernate.search.indexes.impl.IndexManagerHolder.createIndexManagers(IndexManagerHolder.java:482)
    at org.hibernate.search.indexes.impl.IndexManagerHolder.buildEntityIndexBinding(IndexManagerHolder.java:91)
    at org.hibernate.search.spi.SearchIntegratorBuilder.initDocumentBuilders(SearchIntegratorBuilder.java:358)
    at org.hibernate.search.spi.SearchIntegratorBuilder.buildNewSearchFactory(SearchIntegratorBuilder.java:199)
    at org.hibernate.search.spi.SearchIntegratorBuilder.buildSearchIntegrator(SearchIntegratorBuilder.java:117)
    at org.hibernate.search.hcore.impl.HibernateSearchSessionFactoryObserver.sessionFactoryCreated(HibernateSearchSessionFactoryObserver.java:75)
    at org.hibernate.internal.SessionFactoryObserverChain.sessionFactoryCreated(SessionFactoryObserverChain.java:35)
    at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:530)
    at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:444)
    at     org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:879)
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1574)
    ... 21 

我与我的依赖关系和他们的版本杂耍,但没有任何改变 我的依赖

    <!-- Hibernate -->
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-ehcache</artifactId>
        <version>5.0.6.Final</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-core</artifactId>
        <version>5.0.6.Final</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-entitymanager</artifactId>
        <version>5.0.6.Final</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-validator</artifactId>
        <version>5.2.4.Final</version>
    </dependency>
    <dependency>
        <groupId>javax.transaction</groupId>
        <artifactId>jta</artifactId>
        <version>1.1</version>
    </dependency>

    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-search-orm</artifactId>
        <version>5.5.3.Final</version>
    </dependency>

我还使用了ReleaseTrain中的Spring Data JPAHopper-SR1),因此Spring Data JPA 1.10.1

我的Place.class

@Getter
@Setter
@Entity
@Indexed
@Spatial
public class Place implements Serializable {

    private static final long serialVersionUID = -8379536848917838560L;
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Id
    @Column(name = "place_id")
    private Long id;

    //...
    @Longitude
    private Double lng;

    @Latitude
    private Double lat;
    //...
    }

Here is my RepositoryConfig mvn dependency:tree of my parent module

1 个答案:

答案 0 :(得分:2)

看来你正在推出一个不兼容的Lucene版本。你能分享运行mvn dependency:tree的输出吗? Hibernate Search 5.5适用于Lucene 5.3 atm。