如何在ebean&中使用blob玩2?

时间:2012-05-29 23:22:39

标签: blob playframework-2.0 ebean

这是实体包含blob类型:

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

    .......

    @Constraints.Required
    private Blob image;

    .......
}

$ play -DapplyEvolutions.default = true run

我收到如下错误:

[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]

如何进行更改以便识别blob类型?

1 个答案:

答案 0 :(得分:10)

要使用Ebean创建blob,您需要使用带有@Lob注释的字节数组

@Lob
public byte[] image;

很可能你需要在File< - >之间进行转换。字节数组,所以也许在文件系统中存储文件更容易? (除了在FS中存储文件比在DB中便宜)

如果您需要特殊的访问限制,您可以使用自己的控制器来检查权限,并按存储在数据库中的路径从磁盘流式传输文件。