1

I am using play 2.2 with Ebean ORM deployed to Heroku. New to Ebean and I am having trouble. I need to store an image file and am having compatibility issues. Ebean will allow the use of @Lob to create a Blob, or without the tag a longvarbinary. I need a bytea for Postgres. Is it possible to do this? If not, is there any other way of storing an image file?

Edit:

This is the error message I get when attempting to push the local repo, which works fine, to Heroku.

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

This is how it is defined in my model:

@Lob
public byte[] profilePicture;

This is my application.conf settings:

# 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.*"

I also have a Procfile that looks like this.

web: target/universal/stage/bin/hello-play-backbone -Dhttp.port=${PORT} $PLAY_OPTS 
-DapplyEvolutions.default=true -Ddb.default.url=${DATABASE_URL} -Ddb.default.driver=org.postgresql.Driver
MattH
  • 87
  • 2
  • 11
  • 1
    Is this related to this question? http://stackoverflow.com/questions/11569838/what-data-type-does-ebean-map-to-bytea – codefinger Apr 30 '15 at 19:02
  • That is how I was trying to do it. It works fine locally but when pushing to heroku I get the error message that I just added to my original question. – MattH Apr 30 '15 at 19:46
  • 1
    Are you setting `db.default.url=${?DATABASE_URL}` anywhere in `application.conf`? Also, i'm not sure about the H2 driver, I normal set the db conf like this: https://github.com/mkbehbehani/play-heroku-seed/blob/master/conf/application.conf#L40-L44 – codefinger Apr 30 '15 at 20:41
  • 1
    Another thing to consider: if the schema (your *.sql files) were generated for H2, they may be incorrect, even if the mode is set to PostgreSQL. This answer has some good info: http://stackoverflow.com/a/12196800/63308 – codefinger Apr 30 '15 at 21:10
  • They work if I take out the byte[]. I think you are right about it being an H2 problem. Looks like H2 doesn't support bytea. Might be what is wrong. I will try and follow the advice in the links. Thanks – MattH Apr 30 '15 at 21:49

1 Answers1

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

Using the above link provided by @codefinger in the comments above I was able to get this working. Just wanted to update in case anyone else was struggling with this. Turns out H2 does not support bytea. After changing the default db configuration as posted below I was able to generate working DDL and connect to my Heroku database remotely eliminating the need for 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
MattH
  • 87
  • 2
  • 11