在Ebean中的Heroku Postgres bytea

时间:2015-04-30 05:25:49

标签: postgresql heroku playframework playframework-2.0 ebean

我正在使用Play 2.2并将Ebean ORM部署到Heroku。 Ebean新手,我遇到了麻烦。我需要存储一个图像文件,并且存在兼容性问题。 Ebean将允许使用@Lob创建Blob,或者不使用标签longvarbinary。我需要一个用于Postgres的bytea。是否有可能做到这一点?如果没有,还有其他存储图像文件的方法吗?

编辑:

这是我尝试将本地仓库推送到Heroku时出现的错误消息。

$config->set('HTML.Allowed', 'img[src|alt|style],span[style]');

这是我在模型中定义的方式:

2015-04-30T15:43:02.546699+00:00 app[web.1]: Play server process ID is 3
2015-04-30T15:43:04.524027+00:00 app[web.1]: [info] play - database   [default] connected at jdbc:postgresql://ec2-184-73-221-47.compute- 1.amazonaws.com:5432/dcn8fp0jefq7ef
2015-04-30T15:43:05.490712+00:00 app[web.1]: [error] play - ERROR: type "blob" does not exist
2015-04-30T15:43:05.490720+00:00 app[web.1]:   Position: 376 [ERROR:0, SQLSTATE:42704]
2015-04-30T15:43:05.531616+00:00 app[web.1]: Oops, cannot start the server.
2015-04-30T15:43:05.532587+00:00 app[web.1]:    at play.api.db.evolutions.Evolutions$.checkEvolutionsState(Evolutions.scala:193)
2015-04-30T15:43:05.543409+00:00 app[web.1]:    at play.api.db.evolutions.EvolutionsPlugin.onStart(Evolutions.scala:459)
2015-04-30T15:43:05.543526+00:00 app[web.1]:    at play.api.Play$$anonfun$start$1$$anonfun$apply$mcV$sp$1.apply(Play.scala:88)
2015-04-30T15:43:05.543570+00:00 app[web.1]:    at scala.collection.immutable.List.foreach(List.scala:318)
2015-04-30T15:43:05.543479+00:00 app[web.1]:    at play.api.Play$$anonfun$start$1$$anonfun$apply$mcV$sp$1.apply(Play.scala:88)
2015-04-30T15:43:05.543095+00:00 app[web.1]:    at play.api.db.evolutions.Evolutions$.applyScript(Evolutions.scala:277)
2015-04-30T15:43:05.5

这是我的application.conf设置:

@Lob
public byte[] profilePicture;

我还有一个看起来像这样的Procfile。

# Database configuration
# ~~~~~
# You can declare as many datasources as you want.
# By convention, the default datasource is named `default`
#

db.default.driver=org.h2.Driver
db.default.url="jdbc:h2:mem:play;MODE=PostgreSQL"
#
# You can expose this datasource via JNDI if needed (Useful for JPA)
# db.default.jndiName=DefaultDS

# Evolutions
# ~~~~~
# You can disable evolutions if needed
# evolutionplugin=disabled

# Ebean configuration
# ~~~~~
# You can declare as many Ebean servers as you want.
# By convention, the default server is named `default`
#
ebean.default="models.*"

1 个答案:

答案 0 :(得分:0)

http://stackoverflow.com/a/12196800/63308

在上面的评论中使用@codefinger提供的上述链接,我能够正常工作。只是想更新以防其他人在努力解决这个问题。原来H2不支持bytea。更改下面发布的默认数据库配置后,我能够生成工作DDL并远程连接到我的Heroku数据库,无需H2。

db.default.driver=org.postgresql.Driver 
https://postgres.heroku.com/ -> YourDBs -> db-name -> Connection settings -> JDBC URL + &ssl=true&sslfactory=org.postgresql.ssl.NonValidatingFactory