Hibernate Search集成到Play Framework(JPA)中 [英] Hibernate Search integrated into Play Framework (JPA)

查看:226
本文介绍了Hibernate Search集成到Play Framework(JPA)中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将Hibernate Search与Play Framework一起使用。它接缝非常简单直接。但我收到一个异常(见下面):

这是我做的:



我添加了依赖关系

 org.hibernate%hibernate-entitymanager%4.3.8.Final,
org。 hibernate%hibernate-search-orm%5.2.0.Final,

我已经

然后我添加了Hibernate Search属性:



http:// java .sun.com / xml / ns / persistence / persistence_2_0.xsd
version =2.0>

 < ; persistence-unit name =defaulttransaction-type =RESOURCE_LOCAL> 
< provider> org.hibernate.jpa.HibernatePersistenceProvider< / provider>
< non-jta-data-source> ; DefaultDS< / non-jta-data-source>
< class> models.User< / class>
<属性>
< property name =hibernate.dialectvalue =org.hibernate.dialect.MySQLDialect/>
< property name =hibernate。 hbm2ddl.autovalue =update/>

< property name =hibernate.search.default.directory_provider
value =filesystem/>

< property name =hibernate.search.default.indexBase
value =/ var / lucene / indexes/>

< / properties>

< / persistence-unit>





 < property name =hibernate.search.default.directory_provider
value =filesystem/>

< property name =hibernate.search.default.indexBase
value =/ var / lucene / indexes/>

我向用户添加了一些注释:

  @Entity 
@Indexed
public class User extends Model {

@Field(index = Index.YES,analyze = Analyze。 YES,store = Store.NO)
public String firstname;
@Field(index = Index.YES,analyze = Analyze.YES,store = Store.NO)
public String lastname;
}

我启动服务器并尝试访问该网站:

  play.api.UnexpectedException:意外的异常[AbstractMethodError:org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl $ 4.getConfigurationValues()Ljava / util / Map;] 
at play.core.ReloadableApplication $$ anonfun $ get $ 1 $$ anonfun $ apply $ 1 $$ anonfun $ 1.apply(ApplicationProvider.scala:170)〜[play_2.11-2.3.7.jar: 2.3.7]
在play.core.ReloadableApplication $$ anonfun $ get $ 1 $$ anonfun $ apply $ 1 $$ anonfun $ 1.apply(ApplicationProvider.scala:130)〜[play_2.11-2.3.7.jar :2.3.7]
at scala.Option.map(Option.scala:145)〜[scala-library-2.11.4.jar:na]
at play.core.ReloadableApplication $$ anonfun $获得$ 1 $$ anonfun $ apply $ 1.apply(ApplicationProvider.scala:130)〜[play_2.11-2.3.7.jar:2.3.7]
at play.core.ReloadableApplication $$ anonfun $ get $ 1 $ $ anonfun $ apply $ 1.apply(ApplicationProvider.scala:128)〜[play_2.11-2.3.7.jar:2.3.7]
引起:java.lang.AbstractMeth odError:org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl $ 4.getConfigurationValues()Ljava / util / Map;
at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.withTccl(ClassLoaderServiceImpl.java:404)〜[hibernate-core-4.3.9.Final.jar:4.3.9.Final]
在org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:844)〜[hibernate-entitymanager-4.3.8.Final.jar:4.3.8.Final]
at org.hibernate .jpa.HibernatePersistenceProvider.createEntityManagerFactory(HibernatePersistenceProvider.java:75)〜[hibernate-entitymanager-4.3.8.Final.jar:4.3.8.Final]
at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence。 java:54)〜[hibernate-entitymanager-4.3.8.Final.jar:4.3.8.Final]
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:63)〜[hibernate-jpa-2.0 -api-1.0.1.Final.jar:1.0.1.Final]

感谢您的支持帮助。

解决方案

所有从 5.0.0 的Hibernate Search版本 5.3.0 与任何Hibernate ORM版本 4.3.x 4.3.0 )兼容,最新的4.3系列当前版本是 4.3.10 )。



但是你总是必须为 hibernate-entitymanager hibernate选择相同的确切版本-orm ,因为它们一起发布,不应该拆分&混淆。

从stacktrace看来你已经在使用Hibernate ORM版本4.3.9( hibernate-core-4.3。 9.Final.jar ),所以你不应该使用 hibernate-entitymanager-4.3.8.Final ,但是也可以将EntityManager升级到 4.3.9 或将hibernate-core降级到4.3.8 ,或者只升级到 4.3.10 (可能是最好的选择)。



Hibernate兼容性规则

通常,规则是hibernate-core和hibernate-entitymanager需要完全相同的版本;然后查阅Hibernate Search文档,找出它兼容的范围。



这些信息可以在自述文件,位于参考文档或通过 pom.xml (还有很多能够解释Maven元数据的工具)。



兼容性也在下载页面中提到:
- http: http://hibernate.org/search/downloads/



下载页面和pom文件只提到了一个特定的Hibernate ORM版本(它是搭配)。
自述参考文档指定了意图的版本范围兼容;这些都是由人类更新的,所以它有时可能不太准确,但如果这样做不起作用,请提交一个错误,因为我们会努力保持兼容性范围的放松,尤其是在小版本中。



Hibernate的兼容性定义和期望记录在此处: https:/ /github.com/hibernate/hibernate-orm/wiki/Compatibility-Considerations


Im am trying to use Hibernate Search together with Play Framework. It seams very easy and straight forward. But I get a exception (see below):

Here is what I did:

I added dependencies

"org.hibernate" % "hibernate-entitymanager" % "4.3.8.Final",
"org.hibernate" % "hibernate-search-orm" % "5.2.0.Final",

I already had Entitymanager and it works fine.

Then I added the Hibernate Search properties:

http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd" version="2.0">

<persistence-unit name="default" transaction-type="RESOURCE_LOCAL">
    <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
    <non-jta-data-source>DefaultDS</non-jta-data-source>
    <class>models.User</class>
    <properties>
        <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
        <property name="hibernate.hbm2ddl.auto" value="update"/>

        <property name="hibernate.search.default.directory_provider"
                  value="filesystem"/>

        <property name="hibernate.search.default.indexBase"
                  value="/var/lucene/indexes"/>

    </properties>

</persistence-unit>

New about this is only:

        <property name="hibernate.search.default.directory_provider"
                  value="filesystem"/>

        <property name="hibernate.search.default.indexBase"
                  value="/var/lucene/indexes"/>

I added some Annotation to the User:

@Entity
@Indexed
public class User extends Model {

     @Field(index= Index.YES, analyze= Analyze.YES, store= Store.NO)
     public String firstname;
     @Field(index=Index.YES, analyze=Analyze.YES, store=Store.NO)
     public String lastname;
}

I start the Server and try to access the site:

play.api.UnexpectedException: Unexpected exception[AbstractMethodError: org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.getConfigurationValues()Ljava/util/Map;]
    at play.core.ReloadableApplication$$anonfun$get$1$$anonfun$apply$1$$anonfun$1.apply(ApplicationProvider.scala:170) ~[play_2.11-2.3.7.jar:2.3.7]
    at play.core.ReloadableApplication$$anonfun$get$1$$anonfun$apply$1$$anonfun$1.apply(ApplicationProvider.scala:130) ~[play_2.11-2.3.7.jar:2.3.7]
    at scala.Option.map(Option.scala:145) ~[scala-library-2.11.4.jar:na]
    at play.core.ReloadableApplication$$anonfun$get$1$$anonfun$apply$1.apply(ApplicationProvider.scala:130) ~[play_2.11-2.3.7.jar:2.3.7]
    at play.core.ReloadableApplication$$anonfun$get$1$$anonfun$apply$1.apply(ApplicationProvider.scala:128) ~[play_2.11-2.3.7.jar:2.3.7]
Caused by: java.lang.AbstractMethodError: org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.getConfigurationValues()Ljava/util/Map;
    at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.withTccl(ClassLoaderServiceImpl.java:404) ~[hibernate-core-4.3.9.Final.jar:4.3.9.Final]
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:844) ~[hibernate-entitymanager-4.3.8.Final.jar:4.3.8.Final]
    at org.hibernate.jpa.HibernatePersistenceProvider.createEntityManagerFactory(HibernatePersistenceProvider.java:75) ~[hibernate-entitymanager-4.3.8.Final.jar:4.3.8.Final]
    at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:54) ~[hibernate-entitymanager-4.3.8.Final.jar:4.3.8.Final]
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:63) ~[hibernate-jpa-2.0-api-1.0.1.Final.jar:1.0.1.Final]

Thank you for your Help.

解决方案

All Hibernate Search versions from 5.0.0 to 5.3.0 are compatible with any Hibernate ORM version 4.3.x (4.3.0 to latest of the 4.3 series, which currently is 4.3.10).

But you always must choose the same exact version for hibernate-entitymanager and hibernate-orm, as these are released together and should not be split & mixed up.

From the stacktrace it seems you were already using Hibernate ORM version 4.3.9 (hibernate-core-4.3.9.Final.jar), so you should not use hibernate-entitymanager-4.3.8.Final but either upgrade EntityManager to 4.3.9 as well, or downgrade hibernate-core to 4.3.8, or just upgrade both to 4.3.10 (probably the best option).

Hibernate compatibility rules

Generally the rule is that hibernate-core and hibernate-entitymanager need to be at the exact same version; then consult the Hibernate Search documentation to find out for which range it is compatible.

This information can be found in the README, in the reference documentation, or via the pom.xml (also with the many tools able to interpret Maven metadata).

Compatibility is also mentioned in the downloads page: - http://hibernate.org/search/downloads/

The downloads page and the pom file only mention a single, specific Hibernate ORM version (the version it was built with). The README and reference documentation specify the range of versions which are meant to be compatible; these are updated by humans though so it might occasionally be less accurate, but if that wouldn't work please file a bug as we do strive to keep compatibility ranges relaxed, especially among minor versions.

The Compatibility definitions and expectations for Hibernate are documented here: https://github.com/hibernate/hibernate-orm/wiki/Compatibility-Considerations

这篇关于Hibernate Search集成到Play Framework(JPA)中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆