没有名称为defaultPersistenceUnit的EntityManager的持久性提供程序,将不会创建EntitiyManagerFactory

时间:2018-11-27 15:26:50

标签: java hibernate jpa playframework sqlite

我开始使用play框架,我想将其连接到我正在使用hibernate的数据库。该数据库是sqlite3。这是代码: 家用控制器:

public class HomeController extends Controller {
/**
 * An action that renders an HTML page with a welcome message.
 * The configuration in the <code>routes</code> file means that
 * this method will be called when the application receives a
 * <code>GET</code> request with a path of <code>/</code>.
 */


public Result index() {

    Blog blog = new Blog(2,"Amar");
    EntityManagerFactory entityManagerFactory = Persistence.createEntityManagerFactory("defaultPersistenceUnit");


    return ok(views.html.index.render());
}}

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">
    <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
    <non-jta-data-source>DefaultDS</non-jta-data-source>
    <properties>
        <property name="hibernate.dialect" value="org.hibernate.dialect.SQLiteDialect"/>
        <property name="hibernate.hbm2ddl.auto" value="update"/>
    </properties>
</persistence-unit>

复制配置:

db.default.driver=org.sqlite.JDBC
db.default.url="jdbc:sqlite:/C:/Users/Amar/Desktop/javaplay/blogapp/dbfolderblog_database.sqlite3"
db.default.jndiName=DefaultDS

jpa.default=defaultPersistenceUnit

这是位于桌面上的项目的文件夹:

因为我无法创建实体管理器工厂,所以无法将数据推送到数据库中。 发生此错误的原因是:“ PersistenceException:名为默认PersistenceUnit的EntityManager的持久性提供程序”

    [error] application -

! @7a3p0p4d0 - Internal server error, for (GET) [/] ->

play.api.http.HttpErrorHandlerExceptions$$anon$1: Execution exception[[PersistenceException: No Persistence provider for EntityManager named defaultPersistenceUnit]]
        at play.api.http.HttpErrorHandlerExceptions$.throwableToUsefulException(HttpErrorHandler.scala:251)
        at play.api.http.DefaultHttpErrorHandler.onServerError(HttpErrorHandler.scala:178)
        at play.core.server.AkkaHttpServer$$anonfun$1.applyOrElse(AkkaHttpServer.scala:382)
        at play.core.server.AkkaHttpServer$$anonfun$1.applyOrElse(AkkaHttpServer.scala:380)
        at scala.concurrent.Future.$anonfun$recoverWith$1(Future.scala:413)
        at scala.concurrent.impl.Promise.$anonfun$transformWith$1(Promise.scala:37)
        at scala.concurrent.impl.CallbackRunnable.run(Promise.scala:60)
        at akka.dispatch.BatchingExecutor$AbstractBatch.processBatch(BatchingExecutor.scala:55)
        at akka.dispatch.BatchingExecutor$BlockableBatch.$anonfun$run$1(BatchingExecutor.scala:91)
        at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:12)
Caused by: javax.persistence.PersistenceException: No Persistence provider for EntityManager named defaultPersistenceUnit
        at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:61)
        at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:39)
        at controllers.HomeController.index(HomeController.java:29)
        at router.Routes$$anonfun$routes$1.$anonfun$applyOrElse$2(Routes.scala:93)
        at play.core.routing.HandlerInvokerFactory$$anon$3.resultCall(HandlerInvoker.scala:134)
        at play.core.routing.HandlerInvokerFactory$$anon$3.resultCall(HandlerInvoker.scala:133)
        at play.core.routing.HandlerInvokerFactory$JavaActionInvokerFactory$$anon$8$$anon$2$$anon$1.invocation(HandlerInvoker.scala:108)
        at play.core.j.JavaAction$$anon$1.call(JavaAction.scala:88)
        at play.http.DefaultActionCreator$1.call(DefaultActionCreator.java:31)
        at play.core.j.JavaAction.$anonfun$apply$8(JavaAction.scala:138)

0 个答案:

没有答案