Play Framework 2.5.4 Hibernate搜索

时间:2016-08-05 14:37:51

标签: java hibernate playframework hibernate-search playframework-2.5

我使用Play 2.5.4(用Java编码)和Hibernate 5.2.1用JPA。我尝试添加Hibernate Search但在build.sbt中启用它时仍然收到以下错误:

  

play.api.http.HttpErrorHandlerExceptions $$ anon $ 1:执行   exception [[ProvisionException:无法配置,请参阅以下内容   错误:1)注入构造函数时出错,java.lang.AbstractMethodError   在   play.db.jpa.DefaultJPAApi $ JPAApiProvider。(DefaultJPAApi.java:39)   在   play.db.jpa.DefaultJPAApi $ JPAApiProvider.class(DefaultJPAApi.java:34)   同时找到play.db.jpa.DefaultJPAApi $ JPAApiProvider   找到play.db.jpa.JPAApi       对于参数0,在play.db.jpa.TransactionalAction。(TransactionalAction.java:20)
  找到play.db.jpa.TransactionalAction 1错误]]   play.api.http.HttpErrorHandlerExceptions $ .throwableToUsefulException(HttpErrorHandler.scala:280)     在   play.api.http.DefaultHttpErrorHandler.onServerError(HttpErrorHandler.scala:206)     at play.api.GlobalSettings $ class.onError(GlobalSettings.scala:160)     at play.api.DefaultGlobal $ .onError(GlobalSettings.scala:188)at   play.api.http.GlobalSettingsHttpErrorHandler.onServerError(HttpErrorHandler.scala:98)     在   play.core.server.netty.PlayRequestHandler $$ anonfun $ 2 $$ anonfun $ $申请1.applyOrElse(PlayRequestHandler.scala:100)     在   play.core.server.netty.PlayRequestHandler $$ anonfun $ 2 $$ anonfun $ $申请1.applyOrElse(PlayRequestHandler.scala:99)     在   scala.concurrent.Future $$ anonfun $ recoverWith $ 1.适用(Future.scala:344)     在   scala.concurrent.Future $$ anonfun $ recoverWith $ 1.适用(Future.scala:343)     在scala.concurrent.impl.CallbackRunnable.run(Promise.scala:32)at at   play.api.libs.iteratee.Execution $蹦床$ .execute(Execution.scala:70)     在   scala.concurrent.impl.CallbackRunnable.executeWithValue(Promise.scala:40)     在   scala.concurrent.impl.Promise $ DefaultPromise.tryComplete(Promise.scala:248)     在scala.concurrent.Promise $ class.complete(Promise.scala:55)at   scala.concurrent.impl.Promise $ DefaultPromise.complete(Promise.scala:153)     在scala.concurrent.Promise $ class.failure(Promise.scala:104)at   scala.concurrent.impl.Promise $ DefaultPromise.failure(Promise.scala:153)     在scala.concurrent.Future $$ anonfun $ flatMap $ 1.apply(Future.scala:255)     在scala.concurrent.Future $$ anonfun $ flatMap $ 1.apply(Future.scala:249)     在scala.concurrent.impl.CallbackRunnable.run(Promise.scala:32)at at   akka.dispatch.BatchingExecutor $ AbstractBatch.processBatch(BatchingExecutor.scala:55)     在   akka.dispatch.BatchingExecutor $ BlockableBatch $$ anonfun $运行$ 1.适用$ MCV $ SP(BatchingExecutor.scala:91)     在   akka.dispatch.BatchingExecutor $ BlockableBatch $$ anonfun $运行$ 1.适用(BatchingExecutor.scala:91)     在   akka.dispatch.BatchingExecutor $ BlockableBatch $$ anonfun $运行$ 1.适用(BatchingExecutor.scala:91)     在   scala.concurrent.BlockContext $ .withBlockContext(BlockContext.scala:72)     在   akka.dispatch.BatchingExecutor $ BlockableBatch.run(BatchingExecutor.scala:90)     at akka.dispatch.TaskInvocation.run(AbstractDispatcher.scala:39)at   akka.dispatch.ForkJoinExecutorConfigurator $ AkkaForkJoinTask.exec(AbstractDispatcher.scala:405)     在   scala.concurrent.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260)     在   scala.concurrent.forkjoin.ForkJoinPool $ WorkQueue.runTask(ForkJoinPool.java:1339)     在   scala.concurrent.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979)     在   scala.concurrent.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107)   原因:com.google.inject.ProvisionException:无法配置,   看到以下错误:1)注入构造函数时出错,   java.lang.AbstractMethodError at   play.db.jpa.DefaultJPAApi $ JPAApiProvider。(DefaultJPAApi.java:39)   在   play.db.jpa.DefaultJPAApi $ JPAApiProvider.class(DefaultJPAApi.java:34)   同时找到play.db.jpa.DefaultJPAApi $ JPAApiProvider   找到play.db.jpa.JPAApi       对于参数0,在play.db.jpa.TransactionalAction。(TransactionalAction.java:20)
  找到play.db.jpa.TransactionalAction 1错误   com.google.inject.internal.InjectorImpl $ 2.注册(InjectorImpl.java:1025)     在   com.google.inject.internal.InjectorImpl.getInstance(InjectorImpl.java:1051)     在   play.api.inject.guice.GuiceInjector.instanceOf(GuiceInjectorBuilder.scala:405)     在   play.core.j.DefaultJavaHandlerComponents.getAction(JavaAction.scala:142)     在play.core.j.JavaAction $$ anonfun $ 6.apply(JavaAction.scala:91)at at   play.core.j.JavaAction $$ anonfun $ 6.apply(JavaAction.scala:89)at at   scala.collection.IndexedSeqOptimized $ class.foldl(IndexedSeqOptimized.scala:57)     在   scala.collection.IndexedSeqOptimized $ class.foldLeft(IndexedSeqOptimized.scala:66)     在scala.collection.mutable.ArraySeq.foldLeft(ArraySeq.scala:46)at at   play.core.j.JavaAction.apply(JavaAction.scala:89)at   play.api.mvc.Action $$ anonfun $ $申请2 $$ anonfun $ $申请5 $$ anonfun $ $申请7.适用(Action.scala:112)     在   play.api.mvc.Action $$ anonfun $ $申请2 $$ anonfun $ $申请5 $$ anonfun $ $申请7.适用(Action.scala:112)     at play.utils.Threads $ .withContextClassLoader(Threads.scala:21)at at   play.api.mvc.Action $$ anonfun $ $申请2 $$ anonfun $ $申请5.apply(Action.scala:111)     在   play.api.mvc.Action $$ anonfun $ $申请2 $$ anonfun $ $申请5.apply(Action.scala:110)     在scala.Option.map(Option.scala:146)at   play.api.mvc.Action $$ anonfun $ apply $ 2.apply(Action.scala:110)at at   play.api.mvc.Action $$ anonfun $ apply $ 2.apply(Action.scala:103)at at   scala.concurrent.Future $$ anonfun $ flatMap $ 1.适用(Future.scala:251)     ...省略了14个常见帧引起的:   java.lang.AbstractMethodError:null at   org.hibernate.internal.SessionFactoryImpl。(SessionFactoryImpl.java:275)     在   org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:483)     在   org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:888)     在   org.hibernate.jpa.HibernatePersistenceProvider.createEntityManagerFactory(HibernatePersistenceProvider.java:58)     在   javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:55)     在   javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:39)     at play.db.jpa.DefaultJPAApi.lambda $ start $ 1(DefaultJPAApi.java:60)     在java.lang.Iterable.forEach(Iterable.java:75)at   play.db.jpa.DefaultJPAApi.start(DefaultJPAApi.java:59)at at   play.db.jpa.DefaultJPAApi $ JPAApiProvider。(DefaultJPAApi.java:46)     在   play.db.jpa.DefaultJPAApi $ JPAApiProvider $$ FastClassByGuice $$ dcd4cdbd.newInstance()     在   com.google.inject.internal.cglib.reflect。$ FastConstructor.newInstance(FastConstructor.java:40)     在   com.google.inject.internal.DefaultConstructionProxyFactory $ 1.newInstance(DefaultConstructionProxyFactory.java:61)     在   com.google.inject.internal.ConstructorInjector.provision(ConstructorInjector.java:105)     在   com.google.inject.internal.ConstructorInjector.construct(ConstructorInjector.java:85)     在   com.google.inject.internal.ConstructorBindingImpl $ Factory.get(ConstructorBindingImpl.java:267)     在   com.google.inject.internal.ProviderToInternalFactoryAdapter $ 1.call(ProviderToInternalFactoryAdapter.java:46)     在   com.google.inject.internal.InjectorImpl.callInContext(InjectorImpl.java:1103)     在   com.google.inject.internal.ProviderToInternalFactoryAdapter.get(ProviderToInternalFactoryAdapter.java:40)     在   com.google.inject.internal.SingletonScope $ 1.get(SingletonScope.java:145)     在   com.google.inject.internal.InternalFactoryToProviderAdapter.get(InternalFactoryToProviderAdapter.java:41)     在   com.google.inject.internal.BoundProviderFactory.get(BoundProviderFactory.java:61)     在   com.google.inject.internal.SingleParameterInjector.inject(SingleParameterInjector.java:38)     在   com.google.inject.internal.SingleParameterInjector.getAll(SingleParameterInjector.java:62)     在   com.google.inject.internal.ConstructorInjector.provision(ConstructorInjector.java:104)     在   com.google.inject.internal.ConstructorInjector.construct(ConstructorInjector.java:85)     在   com.google.inject.internal.ConstructorBindingImpl $ Factory.get(ConstructorBindingImpl.java:267)     在   com.google.inject.internal.InjectorImpl $ 2 $ 1.call(InjectorImpl.java:1016)     在   com.google.inject.internal.InjectorImpl.callInContext(InjectorImpl.java:1092)     在   com.google.inject.internal.InjectorImpl $ 2.注册(InjectorImpl.java:1012)     ...省略了32个常见帧

在build.sbt:

[...]
  "org.hibernate" % "hibernate-core" % "5.2.1.Final",
  "org.hibernate" % "hibernate-entitymanager" % "5.2.1.Final",
  "mysql" % "mysql-connector-java" % "5.1.36",
  //"org.hibernate" % "hibernate-search-orm" % "5.2.1.Final", -> Uncommenting this results in error
  "org.apache.lucene" % "lucene-core" % "5.3.1",
  "dom4j" % "dom4j" % "1.6"
[...]

application.conf

db.default.driver=com.mysql.jdbc.Driver
db.default.url="jdbc:mysql://localhost/db?autoReconnect=true"
[...db info...]
db.default.jndiName = DefaultDS
jpa.default = defaultPersistenceUnit

的hibernate.cfg.xml

<hibernate-configuration>
    <session-factory>
    <!-- Database connection settings -->
    <property name="connection.driver_class">com.mysql.jdbc.Driver</property>
    <property name="connection.url">jdbc:mysql://localhost/db?autoReconnect=true</property>
    <property name="connection.username">###</property>
    <property name="connection.password">###</property>

    <!-- JDBC connection pool (use the built-in) -->
    <property name="connection.pool_size">1</property>

    <!-- SQL dialect -->
    <property name="dialect">org.hibernate.dialect.MySQLDialect</property>

    <!-- Enable Hibernate's automatic session context management -->
    <property name="current_session_context_class">thread</property>

    <!-- Disable the second-level cache -->
    <property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>

    <!-- Echo all executed SQL to stdout -->
    <property name="show_sql">true</property>


</session-factory>
</hibernate-configuration>

的persistence.xml

    <persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence"
                 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                 xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"
                 version="2.1">
        <persistence-unit name="defaultPersistenceUnit" transaction-type="RESOURCE_LOCAL">
            <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
            <non-jta-data-source>DefaultDS</non-jta-data-source>
            <properties>
                <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
        </properties>

    </persistence-unit>
</persistence>

我似乎无法找到关于如何在Play Framework 2.5 +中使用Hibernate Search的好教程。

谢谢!

LE

我通过使用:

来解决它
...
  "org.hibernate" % "hibernate-entitymanager" % "4.3.10.Final",
  "org.hibernate" % "hibernate-search-orm" % "5.3.0.Final",
...

如此处所示:https://stackoverflow.com/a/30656145/6682875

2 个答案:

答案 0 :(得分:0)

您的配置似乎缺少一些东西。 以下是我使用的工作配置示例(仅替换实名)。注意,没有使用hibernate.cfg.xml。

build.sbt:

val hibernateVersion = "4.3.10.Final"
val mySqlConnectorVersion = "5.1.36"

libraryDependencies ++= Seq(
  javaJpa
)
...
libraryDependencies ++= Seq(
    ...
    "org.hibernate" % "hibernate-entitymanager" % hibernateVersion,
    "mysql" % "mysql-connector-java" % mySqlConnectorVersion
    ...

application.conf:

# ~~~~~
# MySql 5.6
db.default.driver=com.mysql.jdbc.Driver
db.default.username="user" - put here your DB user name
db.default.password="password" - put here your DB user password
dbhosts="hostip:port" - put here your host and DB port
dbschema="dbschema" - put here the exact case-sensitive name of the DB schema
dbproperties="?autoReconnect=true"
db.default.url="mysql://"${db.default.username}":"${db.default.password}"@"${dbhosts}"/"${dbschema}${dbproperties}
db.default.jndiName=MyDS
jpa.default=myDbPersistanceUnit

的persistence.xml:

<persistence-unit name="myDbPersistanceUnit" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<non-jta-data-source>MyDS</non-jta-data-source>
    <!--Model mapping (optional) like below-->
    <!--class>persistence.models.SomeEntityClass</class>-->
    ....
<properties>
    <!--Hibernate properties -->
    <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" />
    <property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver" />
</properties>

答案 1 :(得分:0)

我通过使用:

来解决它
...
  "org.hibernate" % "hibernate-entitymanager" % "4.3.10.Final",
  "org.hibernate" % "hibernate-search-orm" % "5.3.0.Final",
...

如此处所示:https://stackoverflow.com/a/30656145/6682875