我一直在嘗試使用Play Framework 2.4.0,JPA和Hibernate 4.3.9來創建一個簡單和小型的應用程序來連接到PostgreSQL 9.4數據庫。我希望應用程序根據應用程序上創建的模型創建新的數據庫表。到目前爲止,我沒有成功。Play + JPA + Hibernate + PostgreSQL:無法創建表
這是我的 「build.sbt」 的內容:
name := """aplicacion1"""
version := "1.0-SNAPSHOT"
lazy val root = (project in file(".")).enablePlugins(PlayJava)
scalaVersion := "2.11.6"
libraryDependencies ++= Seq(
javaJdbc,
cache,
javaJpa,
//"org.apache.directory.api" % "apache-ldap-api" % "1.0.0-M14",
"postgresql" % "postgresql" % "9.1-901-1.jdbc4",
"org.hibernate" % "hibernate-core" % "4.3.9.Final",
"org.hibernate" % "hibernate-entitymanager" % "4.3.9.Final"
)
// Play provides two styles of routers, one expects its actions to be injected, the
// other, legacy style, accesses its actions statically.
routesGenerator := InjectedRoutesGenerator
這是我的 「application.conf」 描述的數據庫連接如內容:
db.default.driver=org.postgresql.Driver
db.default.url="postgres://postgres:[email protected]/tesis_play1"
db.default.jndiName=DefaultDS
jpa.default=defaultPersistenceUnit
這是內容我的「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.PostgreSQL9Dialect"/>
<property name="hibernate.hbm2ddl.auto" value="update"/>
</properties>
</persistence-unit>
</persistence>
這是我試圖進入數據庫的小型模型類:
@Entity
public class ruta {
@Id
public int idRuta;
public String nombre;
public boolean esIda;
public boolean esvuelta;
public String apodo1;
public String apodo2;
public String ref;
}
應用程序編譯並運行時沒有錯誤,但從不在數據庫上創建「ruta」表。有什麼我失蹤?謝謝您的幫助!
編輯: 「本地主機:9000」:通過訪問應用程序時,控制檯上出現以下
[info] Compiling 2 Java sources to C:\Users\Enrique\Desktop\tesis_2\aplicacion1\target\scala-2.11\classes...
SLF4J: The following set of substitute loggers may have been accessed
SLF4J: during the initialization phase. Logging calls during this
SLF4J: phase were not honored. However, subsequent logging calls to these
SLF4J: loggers will work as normally expected.
SLF4J: See also http://www.slf4j.org/codes.html#substituteLogger
SLF4J: org.webjars.CloseQuietly
[info] - application - Creating Pool for datasource 'default'
[info] - play.api.db.HikariCPConnectionPool - datasource [jdbc:postgresql://localhost/tesis_play1] bound to JNDI as DefaultDS
[info] - play.api.db.DefaultDBApi - Database [default] connected at jdbc:postgresql://localhost/tesis_play1
[info] - play.api.libs.concurrent.ActorSystemProvider - Starting application default Akka system: application
[info] - play.api.Play$ - Application started (Dev)
我不是JPA的專家,但也許在你application.conf行'db.default.url'是錯誤的:一般情況下它看起來更像是'jdbc:postgresql:// localhost:5432/test_database'和密碼和用戶名,您可能需要在其他行中定義'db.default.user = myusername'和'db.default.password = mypassword' 。 – Kris
@Kris我試過這樣,但結果是一樣的:表仍然沒有被創建:( – Eduardo
什麼是在你的日誌,如果你添加' '到你的persistance.xml? –
Kris