玩框架 2.8 和 postgreSQL 12.5

play framwork 2.8 and postgreSQL 12.5

你好亲爱的社区和技术喜悦, 我用 postgresql 12.5 创建了一个新的 Play framwork 2.8 项目。

postgreSql中没有auto_increment。这里只有(小,大)连载PostgreSQL - AUTO INCREMENT.

但是,Play 尝试用 auto_increment 创建一个 table。这不顺利是合乎逻辑的。

create table project_type (
  id bigint auto_increment not null,
  name varchar (255),
  constraint pk_project_type primary key (id)
);
psql -V
psql (PostgreSQL) 12.5 (Ubuntu 12.5-0ubuntu0.20.04.1)

play version: addSbtPlugin ("com.typesafe.play"% "sbt-plugin"% "2.8.5")

我的配置有什么问题?

application.conf

play {

    modules {
        enabled += "play.api.db.DBModule"
        enabled += "play.api.db.HikariCPModule"
    }
    ebean.default = ["models.*"]
    crypto.secret = "aKr4Mfn!vKzDjfhfdJRsakgbPS35!!HVDldkosGHRT"
}

applyEvolutions.default=true
db.default{
    driver = org.postgresql.Driver
    url= "jdbc:postgresql://localhost:5432/meineSeite"
    username = "andi1"
    password = "andi1"
}

# Root logger:
logger=ERROR

# Logger used by the framework:
logger.play=INFO

# Logger provided to your application:
logger.application=DEBUG

build.sbt

name := """meineSeite"""
organization := "com.af86"

version := "1.0-SNAPSHOT"

lazy val root = (project in file("."))
  .enablePlugins(PlayJava, PlayEbean)
  .settings(
    name := "play-java-ebean-example",
    version := "1.0.0-SNAPSHOT",
    scalaVersion := "2.13.1",
    libraryDependencies ++= Seq(
      guice,
      jdbc,
      javaJdbc,
      "mysql" % "mysql-connector-java" % "5.1.41",
      "org.postgresql"     % "postgresql"   % "9.3-1102-jdbc41",
      "org.postgresql" % "postgresql" % "42.2.12",
      "javax.xml.bind"     % "jaxb-api"     % "2.3.1",
      "javax.activation"   % "activation"   % "1.1.1",
      "org.glassfish.jaxb" % "jaxb-runtime" % "2.3.2"
    )
  )

scalaVersion := "2.13.3"

plugins.sbt

// The Play plugin
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.8.5")

// Defines scaffolding (found under .g8 folder)
// http://www.foundweekends.org/giter8/scaffolding.html
// sbt "g8Scaffold form"
addSbtPlugin("org.foundweekends.giter8" % "sbt-giter8-scaffold" % "0.11.0")

addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.8.5")

addSbtPlugin("com.typesafe.sbt" % "sbt-play-ebean" % "5.0.2")

现在可以使用了 ;-)

conf.META-INF.persistence.xml

<persistence xmlns="http://java.sun.com/xml/ns/persistence"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
             version="2.0">

    <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.PostgreSQLDialect"/>
            <property name="hibernate.hbm2ddl.auto" value="update"/>
            <property name="hibernate.format_sql" value="true"/>
            <property name="hibernate.show_sql" value="true"/> <!-- show sql in consol -->
        </properties>
    </persistence-unit>ac
</persistence>

application.conf

evolutions.enabled="false"

build.sbt

name := """meineSeite"""
organization := "com.af86"

version := "1.0-SNAPSHOT"

lazy val root = (project in file("."))
  .enablePlugins(PlayJava, PlayEbean)
  .settings(
    name := "play-java-ebean-example",
    version := "1.0.0-SNAPSHOT",
    scalaVersion := "2.13.3",
    libraryDependencies ++= Seq(
      guice,
      jdbc,
      javaJdbc,
      javaJpa,
      "org.hibernate" % "hibernate-core" % "5.4.9.Final",
      "org.postgresql" % "postgresql" % "9.4.1212",
      "javax.xml.bind"     % "jaxb-api"     % "2.3.1",
      "javax.activation"   % "activation"   % "1.1.1",
      "org.glassfish.jaxb" % "jaxb-runtime" % "2.3.2"
    )
  )

scalaVersion := "2.13.3"

PlayKeys.externalizeResourcesExcludes += baseDirectory.value / "conf" / "META-INF" / "persistence.xml"