问题
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.
回答1:
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
回答2:
Solved thanks to User mhlz in the comments.Seams I had to update the Entity-manager.
来源:https://stackoverflow.com/questions/30621230/hibernate-search-integrated-into-play-framework-jpa