2012-05-29 21 views
5

Đây là thực thể chứa loại blob:Làm thế nào để sử dụng blob với ebean & play 2?

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

    ....... 

    @Constraints.Required 
    private Blob image; 

    ....... 
} 

$ chơi -DapplyEvolutions.default = chạy đúng

Tôi đã nhận lỗi như sau:

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

Làm thế nào tôi có thể thực hiện thay đổi vì vậy blob loại có thể được công nhận?

Trả lời

10

Để tạo blob với Ebean bạn cần phải sử dụng mảng byte với @Lob chú thích

@Lob 
public byte[] image; 

Hầu hết có lẽ bạn sẽ cần phải chuyển đổi giữa tập tin < - mảng> byte, vì vậy có lẽ nó dễ dàng hơn để lưu trữ tập tin trong hệ thống tập tin ? (ngoài việc lưu trữ tệp trong FS chỉ rẻ hơn DB)

Nếu bạn cần giới hạn truy cập đặc biệt, bạn có thể sử dụng bộ điều khiển riêng để kiểm tra quyền và truyền tệp từ đĩa theo đường dẫn được lưu trong DB.

+0

Cảm ơn. Tôi có một lỗi trên Heroku nói 'L ERI: loại' blob 'không tồn tại'. Tôi đã thử sử dụng 'play run' ở địa phương của tôi, nó hoạt động. Nhưng không phải Heroku. – angelokh

+0

Heroku sử dụng Postgres theo mặc định và có thể bạn đang phát triển localy với MySQL (lưu ý: Tôi chỉ đang cố đoán). Postgres [không hỗ trợ blob] (http://www.postgresql.org/docs/current/interactive/datatype-binary.html) – biesior

Các vấn đề liên quan