Hibernate无法在Heroku postgres上自动创建模式 [英] Hibernate unable to create schema automatically on Heroku postgres

查看:120
本文介绍了Hibernate无法在Heroku postgres上自动创建模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个播放2.4 hibernate postgresql应用程序,它在本地运行良好,最初自动创建一个表。但是,当部署在heroku上时,它不会创建任何表,尽管该应用程序没有任何错误加载(从pgAdmin连接到我的heroku数据库)。 My Configuration

build.sbt

  name:=lms

version:=1.0

lazy val`lms` =(项目文件(。))。enablePlugins(PlayJava)

scalaVersion:=2.11.7

libraryDependencies ++ = Seq(javaJdbc,cache,javaWs,
javaJpa.exclude(org.hibernate.javax .persistence,hibernate-jpa-2.0-api),
postgresql%postgresql%9.1-901-1.jdbc4,
org.hibernate%hibernate- entitymanager%5.0.1.Final,
net.sf.dozer%dozer%5.4.0)

unmanagedResourceDirectories in Test< + = baseDirectory( _ /target / web / public / test)

解析器+ =scalaz-bintray,位于https://dl.bintray.com/scalaz/releases
code>

application.conf

 #这是应用程序的主要配置文件。 
#~~~~~

#密钥
#~~~~~
#密钥用于保护密码功能。
#如果您将应用程序部署到多个实例,请务必使用相同的密钥!
application.secret =%APPLICATION_SECRET%

#应用语言
#~~~~~
application.langs =en

#全局对象类
#~~~~~
#为此应用程序定义全局对象类。在根包中
#默认为Global。
#application.global =全局

#路由器
#~~~~~
#定义用于此应用程序的路由器对象。
#当应用程序启动时,这个路由器将被首先查找,
#因此确保这是入口点。
#此外,假设您的路由文件命名正确。
#因此对于类似`my.application.Router`,
#的应用程序路由器,您可能需要定义一个路由器文件`conf / my.application.routes`。
#默认路由到根包(和conf /路由)
#application.router = my.application.Routes

#数据库配置
#~~ ~~~
#您可以根据需要声明尽可能多的数据源。
#按照惯例,默认数据源被命名为`default`

db.default.driver = org.postgresql.Driver
db.default.url = $ {?DATABASE_URL }



db.default.jndiName = DefaultDS
jpa.default = defaultPersistenceUnit
db.default.hikaricp.connectionTestQuery =SELECT TRUE
#进化
#~~~~~
#如果需要可以禁用evolution
#evolutionplugin = disabled

#Logger
#〜 ~~~~
#您还可以通过在conf目录中提供application-logger.xml文件来配置logback(http://logback.qos.ch/),
#。

#根记录器:
logger.root =错误

#框架使用的记录器:
logger.play = INFO

#Logger提供给您的应用程序:
logger.application = DEBUG


db.default.logStatements = true

persistence.xml

 <?xml version =1.0encoding =UTF-8?> 
< 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 =defaultPersistenceUnittransaction-type =RESOURCE_LOCAL>
< provider> org.hibernate.jpa.HibernatePersistenceProvider< / provider>
<非-jta-data-source> DefaultDS< /非-jta-data-source>
<属性>
< property name =hibernate.dialectvalue =org.hibernate.dialect.PostgreSQL82Dialect/>
< property name =hibernate.hbm2ddl.autovalue =create/>
< property name =hibernate.show_sqlvalue =true/>
< property name =javax.persistence.sql-load-script-source
value =META-INF / sql / data.sql/>
< / properties>

< / persistence-unit>

< /持久性>

Procfile

  web:target / universal / stage / bin / lms -Dhttp.port = $ {PORT} -Dplay.evolutions.db.default.autoApply = true -Ddb.default.url = $ {DATABASE_URL} 

是否有任何更改需要我首先在heroku上创建数据库模式Postgres的?可能是这个问题?



编辑:

  E:\\ \\ Projects \ lms \LMS> heroku buildpacks 
=== leadmanagementsystem Buildpack URL
heroku / scala

E:\Projects\lms\LMS> heroku config
=== leadmanagementsystem Config Vars
DATABASE_URL:postgres:// aaa:111@dasdsfsv.compute-1.amazonaws.com:5432 / dfregv

E:\项目\lms\LMS> heroku运行echo $ JDBC_DATABASE_URL
在leadmanagementsystem上运行echo $ JDBC_DATABASE_URL ...!
! ENOTFOUND:getaddrinfo ENOTFOUND api.heroku.com api.heroku.com:443


解决方案 div>

终于想通了。



我读过仔细观看2.4.x JavaJPA文档






<使用JPA在开发模式下运行Play可以正常工作,但为了部署应用程序,您需要将它添加到build.sbt文件中。

  PlayKeys.externalizeResources:= false 






添加上面的行解决了问题。


I have a play 2.4 hibernate postgresql application which works well locally, creates a table automatically initially. But when deployed on heroku it does not create any table though the app loaded without any errors(connected my heroku db from pgAdmin). My Configuration

build.sbt

name := "lms"

version := "1.0"

lazy val `lms` = (project in file(".")).enablePlugins(PlayJava)

scalaVersion := "2.11.7"

libraryDependencies ++= Seq(javaJdbc, cache, javaWs,
  javaJpa.exclude("org.hibernate.javax.persistence", "hibernate-jpa-2.0-api"),
  "postgresql" % "postgresql" % "9.1-901-1.jdbc4",
  "org.hibernate" % "hibernate-entitymanager" % "5.0.1.Final",
  "net.sf.dozer" % "dozer" % "5.4.0")

unmanagedResourceDirectories in Test <+= baseDirectory(_ / "target/web/public/test")

resolvers += "scalaz-bintray" at "https://dl.bintray.com/scalaz/releases"  

application.conf

# This is the main configuration file for the application.
# ~~~~~

# Secret key
# ~~~~~
# The secret key is used to secure cryptographics functions.
# If you deploy your application to several instances be sure to use the same key!
application.secret = "%APPLICATION_SECRET%"

# The application languages
# ~~~~~
application.langs = "en"

# Global object class
# ~~~~~
# Define the Global object class for this application.
# Default to Global in the root package.
# application.global=Global

# Router
# ~~~~~
# Define the Router object to use for this application.
# This router will be looked up first when the application is starting up,
# so make sure this is the entry point.
# Furthermore, it's assumed your route file is named properly.
# So for an application router like `my.application.Router`,
# you may need to define a router file `conf/my.application.routes`.
# Default to Routes in the root package (and conf/routes)
# application.router=my.application.Routes

# Database configuration
# ~~~~~
# You can declare as many datasources as you want.
# By convention, the default datasource is named `default`
#
db.default.driver=org.postgresql.Driver
db.default.url=${?DATABASE_URL}



db.default.jndiName = DefaultDS
jpa.default = defaultPersistenceUnit
db.default.hikaricp.connectionTestQuery="SELECT TRUE"
# Evolutions
# ~~~~~
# You can disable evolutions if needed
# evolutionplugin=disabled

# Logger
# ~~~~~
# You can also configure logback (http://logback.qos.ch/),
# by providing an application-logger.xml file in the conf directory.

# Root logger:
logger.root = ERROR

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

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


db.default.logStatements = true

persistence.xml

<?xml version="1.0" encoding="UTF-8"?>
<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.PostgreSQL82Dialect"/>
            <property name="hibernate.hbm2ddl.auto" value="create"/>
            <property name="hibernate.show_sql" value="true"/>
            <property name="javax.persistence.sql-load-script-source"
                      value="META-INF/sql/data.sql"/>
        </properties>

    </persistence-unit>

</persistence>

Procfile

web: target/universal/stage/bin/lms -Dhttp.port=${PORT} -Dplay.evolutions.db.default.autoApply=true -Ddb.default.url=${DATABASE_URL}

Is there any more changes I have to do to create the database schema initially on heroku postgres? What could be the problem?

EDIT:

E:\Projects\lms\LMS>heroku buildpacks
=== leadmanagementsystem Buildpack URL
heroku/scala

E:\Projects\lms\LMS>heroku config
=== leadmanagementsystem Config Vars
DATABASE_URL: postgres://aaa:111@dasdsfsv.compute-1.amazonaws.com:5432/dfregv

E:\Projects\lms\LMS>heroku run "echo $JDBC_DATABASE_URL"
Running echo $JDBC_DATABASE_URL on leadmanagementsystem... !
 !    ENOTFOUND: getaddrinfo ENOTFOUND api.heroku.com api.heroku.com:443

解决方案

Finally figured out.

I dint read Play 2.4.x JavaJPA docs carefully.


Running Play in development mode while using JPA will work fine, but in order to deploy the application you will need to add this to your build.sbt file.

PlayKeys.externalizeResources := false


Adding the above line resolved the issue.

这篇关于Hibernate无法在Heroku postgres上自动创建模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆