Hibernate NoSuchFieldError: INSTANCE

冷暖自知 提交于 2020-01-06 13:29:37

问题


I'm trying to integrate Hibernate Search with Spring Data JPA, so I wrote a sample code to test it.

@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();
}

And I'm getting exception with following stacktrace.

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 

I'm juggling with my dependencies and their versions but nothing changes.
My dependencies

    <!-- 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>

I'm also using Spring Data JPA from ReleaseTrain (Hopper-SR1) so it's Spring Data JPA 1.10.1

My 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:


It seems you are pulling in a non-compatible version of Lucene. Can you share the output of running mvn dependency:tree? Hibernate Search 5.5 works with Lucene 5.3 atm.



来源:https://stackoverflow.com/questions/37794566/hibernate-nosuchfielderror-instance

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!