【问题标题】:Reading Blob from postgres using Hibernate Mapping not using Hibernate Annotations使用 Hibernate Mapping 不使用 Hibernate Annotations 从 postgres 读取 Blob
【发布时间】:2017-08-14 09:17:48
【问题描述】:

当我使用 Hibernate Mapping 时,如何从数据库中读取 blob。我可以将图像保存在数据库中。但是读取数据库中的 blob 字段会产生问题。你能指导我在不使用 Hibernate 注释的情况下逐步从 postgres 数据库中读取 blob。我正在使用休眠映射。

【问题讨论】:

    标签: hibernate blob lob


    【解决方案1】:

    创建这样的实体

    @Entity
    @Table(name = "core_file")
    @SequenceGenerator(name = "default_gen", sequenceName = "seq_core_file", allocationSize = 1)
    public class FileProvider extends BaseEntity<Long> {
    
        @Column(name = "attachment", nullable = false)
        private byte[]  attachment;
    
        @Column(name = "file_Name")
        private String  fileName;
    
        @Column(name = "file_Type", nullable = false)
        private String  mimeType;
    
        @Column(name = "file_Code", nullable = false)
        private String  fileCode;
    
        @Column(name = "accept_date")
        private String  acceptDate;
    
    
    
        public FileProvider() {
            super();
        }
    
        public FileProvider(byte[] attachment, String fileName, String mimeType) {
            super();
            this.attachment = attachment;
            this.fileName = fileName;
            this.mimeType = mimeType;
        }
    
        public byte[] getAttachment() {
            return attachment;
        }
    
        public void setAttachment(byte[] attachment) {
            this.attachment = attachment;
        }
    
        public String getFileName() {
            return fileName;
        }
    
        public void setFileName(String fileName) {
            this.fileName = fileName;
        }
    
        public String getMimeType() {
            return mimeType;
        }
    
        public void setMimeType(String mimeType) {
            this.mimeType = mimeType;
        }
    
        public String getFileCode() {
            return fileCode;
        }
    
        public void setFileCode(String fileCode) {
            this.fileCode = fileCode;
        }
    
        public String getAcceptDate() {
            return acceptDate;
        }
    
        public void setAcceptDate(String acceptDate) {
            this.acceptDate = acceptDate;
        }
    
    }
    

    【讨论】:

    • 我正在使用 org.hibernate.type.BlobType。在这里,您使用的是 Byte[] 数组。我正在使用 Blob 类型。 getBlob 和 setBlob 方法
    • 我们不应该保存具有大小的数据,即大尺寸
    • 我用这种方式大小尺寸都没有问题,你的问题是什么????!!!
    猜你喜欢
    • 2017-02-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-10
    • 2011-02-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多