How to use blob with ebean & play 2?
Asked Answered
S

1

5

This is the entity contains blob type:

@Entity
@Table(name="image_info")
public class ImageInfo extends Model {

    .......

    @Constraints.Required
    private Blob image;

    .......
}

$ play -DapplyEvolutions.default=true run

I got errors like the following:

[warn] c.j.b.ConnectionPartition - BoneCP detected an unclosed connection and will now attempt to close it for you. You should be closing this connection in your application - enable connectionWatch for additional debugging assistance.
[error] c.a.e.s.t.r.ImmutableMetaFactory - Was unable to use reflection to find a constructor and appropriate getters forimmutable type interface java.sql.Blob.  The errors while looking for the getter methods follow:
[error] c.a.e.s.d.p.DeployCreateProperties - Error with models.ImageInfo field:image
java.lang.RuntimeException: Unable to use reflection to build ImmutableMeta for interface     java.sql.Blob.  Associated Errors trying to find a constructor and getter methods have been logged
at com.avaje.ebeaninternal.server.type.reflect.ImmutableMetaFactory.createImmutableMeta(ImmutableMetaFactory.java:71) ~[ebean.jar:na]
at com.avaje.ebeaninternal.server.type.DefaultTypeManager.recursiveCreateScalarTypes(DefaultTypeManager.java:227) ~[ebean.jar:na]
at com.avaje.ebeaninternal.server.deploy.parse.DeployCreateProperties.createProp(DeployCreateProperties.java:357) [ebean.jar:na]
at com.avaje.ebeaninternal.server.deploy.parse.DeployCreateProperties.createProp(DeployCreateProperties.java:377) [ebean.jar:na]
at com.avaje.ebeaninternal.server.deploy.parse.DeployCreateProperties.createProperties(DeployCreateProperties.java:168) [ebean.jar:na]
at com.avaje.ebeaninternal.server.deploy.parse.DeployCreateProperties.createProperties(DeployCreateProperties.java:94) [ebean.jar:na]

How could I make the change so blob type can be recognized?

Sissie answered 29/5, 2012 at 23:22 Comment(0)
A
10

To create blob with Ebean you need to use byte array with @Lob annotation

@Lob
public byte[] image;

Most probably you'll need to convert between File <-> byte array, so maybe it's easier to store files in filesystem? (besides storing files in FS is just cheaper than in DB)

If you need special access restrictions, you can use own controller to check permissions and stream the file from disk by path stored in the DB.

Ammerman answered 30/5, 2012 at 1:11 Comment(2)
Thanks. I got one error on Heroku saying 'ERROR: type "blob" does not exist'. I tried using 'play run' in my local, it works. But not Heroku.Sissie
Heroku uses Postgres by default and probably you're developing localy with MySQL (note: I'm just trying to guess). Postgres does not support blobAmmerman

© 2022 - 2024 — McMap. All rights reserved.