图像未存储在 postgres 中

发布于 2024-10-27 13:14:54 字数 4273 浏览 0 评论 0原文

我已在 MSSQL 中以二进制格式的图像数据类型存储图像。现在我已将数据库从 MSSQL 迁移到 Postgres 9.0 并尝试将图像文件存储在 bytea 字段中。当我尝试将这些字节转换为图像文件时,尽管我没有出现任何错误,但图像未渲染,因为相同的 java 代码在 MSSQL 上运行良好。我的应用程序是基于 struts hibernate 的应用程序。我的 hibernate dto 如下 -

@Entity
@Table(name="Image_Type")
public class ImageType extends AbstractPO
 {


    private static final long serialVersionUID = 1L;

    private Long id;
    private Long ownerId;
    private Short ownerType;
    private String name;
    private String description;
    private Long typeId;
    private byte[] originalImage;
    private byte[] thumbNailImage;
    private byte[] terminalImage;
    private String createdBy;
    private Date createdOn;
    private String modifiedBy;
    private Date modifiedOn;
    private String rfu1;
    private String rfu2;
    private String rfu3;

    @Id @GeneratedValue(strategy=AUTO, generator="Image_Type_seq")
     @SequenceGenerator(name="Image_Type_seq", sequenceName="IMAGE_TYPE_IMAGE_TYPEID_SEQ")

    @Column(name="Image_TypeID", unique=true, nullable=false, precision=10, scale=0)
    public Long getId() {
        return this.id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    @Column(name="OwnerID", precision=10, scale=0)
    public Long getOwnerId() {
        return this.ownerId;
    }

    public void setOwnerId(Long ownerId) {
        this.ownerId = ownerId;
    }

    @Column(name="OwnerType", precision=4, scale=0)
    public Short getOwnerType() {
        return this.ownerType;
    }

    public void setOwnerType(Short ownerType) {
        this.ownerType = ownerType;
    }

    @Column(name="Name", length=100)
    public String getName() {
        return this.name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Column(name="Description", length=100)
    public String getDescription() {
        return this.description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    @Column(name="TypeID", precision=10, scale=0)
    public Long getTypeId() {
        return this.typeId;
    }

    public void setTypeId(Long typeId) {
        this.typeId = typeId;
    }

    @Column(name="Original_Image")
    public byte[] getOriginalImage() {
        return this.originalImage;
    }

    public void setOriginalImage(byte[] originalImage) {
        this.originalImage = originalImage;
    }

    @Column(name="ThumbNail_Image")
    public byte[] getThumbNailImage() {
        return this.thumbNailImage;
    }

    public void setThumbNailImage(byte[] thumbNailImage) {
        this.thumbNailImage = thumbNailImage;
    }

    @Column(name="Terminal_Image")
    public byte[] getTerminalImage() {
        return this.terminalImage;
    }

    public void setTerminalImage(byte[] terminalImage) {
        this.terminalImage = terminalImage;
    }

    @Column(name="CreatedBy", length=50)
    public String getCreatedBy() {
        return this.createdBy;
    }

    public void setCreatedBy(String createdBy) {
        this.createdBy = createdBy;
    }

    @Column(name="CreatedOn", nullable=false, length=23)
    public Date getCreatedOn() {
        return this.createdOn;
    }

    public void setCreatedOn(Date createdOn) {
        this.createdOn = createdOn;
    }

    @Column(name="ModifiedBy", length=50)
    public String getModifiedBy() {
        return this.modifiedBy;
    }

    public void setModifiedBy(String modifiedBy) {
        this.modifiedBy = modifiedBy;
    }

    @Column(name="ModifiedOn", length=23)
    public Date getModifiedOn() {
        return this.modifiedOn;
    }

    public void setModifiedOn(Date modifiedOn) {
        this.modifiedOn = modifiedOn;
    }

    @Column(name="RFU1", length=100)
    public String getRfu1() {
        return this.rfu1;
    }

    public void setRfu1(String rfu1) {
        this.rfu1 = rfu1;
    }

    @Column(name="RFU2", length=100)
    public String getRfu2() {
        return this.rfu2;
    }

    public void setRfu2(String rfu2) {
        this.rfu2 = rfu2;
    }

    @Column(name="RFU3", length=100)
    public String getRfu3() {
        return this.rfu3;
    }

    public void setRfu3(String rfu3) {
        this.rfu3 = rfu3;
    }




}  

请帮助我解决此问题

I have stored images in image data type in binary format in MSSQL.Now I have migrated my database from MSSQL to Postgres 9.0 and trying to store image files in bytea field.When I am trying to convert these bytes into image file though I am not getting any error but Image is not getting rendered where as the same java code is working fine with MSSQL.My application is struts hibernate based application.My hibernate dto is like following-

@Entity
@Table(name="Image_Type")
public class ImageType extends AbstractPO
 {


    private static final long serialVersionUID = 1L;

    private Long id;
    private Long ownerId;
    private Short ownerType;
    private String name;
    private String description;
    private Long typeId;
    private byte[] originalImage;
    private byte[] thumbNailImage;
    private byte[] terminalImage;
    private String createdBy;
    private Date createdOn;
    private String modifiedBy;
    private Date modifiedOn;
    private String rfu1;
    private String rfu2;
    private String rfu3;

    @Id @GeneratedValue(strategy=AUTO, generator="Image_Type_seq")
     @SequenceGenerator(name="Image_Type_seq", sequenceName="IMAGE_TYPE_IMAGE_TYPEID_SEQ")

    @Column(name="Image_TypeID", unique=true, nullable=false, precision=10, scale=0)
    public Long getId() {
        return this.id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    @Column(name="OwnerID", precision=10, scale=0)
    public Long getOwnerId() {
        return this.ownerId;
    }

    public void setOwnerId(Long ownerId) {
        this.ownerId = ownerId;
    }

    @Column(name="OwnerType", precision=4, scale=0)
    public Short getOwnerType() {
        return this.ownerType;
    }

    public void setOwnerType(Short ownerType) {
        this.ownerType = ownerType;
    }

    @Column(name="Name", length=100)
    public String getName() {
        return this.name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Column(name="Description", length=100)
    public String getDescription() {
        return this.description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    @Column(name="TypeID", precision=10, scale=0)
    public Long getTypeId() {
        return this.typeId;
    }

    public void setTypeId(Long typeId) {
        this.typeId = typeId;
    }

    @Column(name="Original_Image")
    public byte[] getOriginalImage() {
        return this.originalImage;
    }

    public void setOriginalImage(byte[] originalImage) {
        this.originalImage = originalImage;
    }

    @Column(name="ThumbNail_Image")
    public byte[] getThumbNailImage() {
        return this.thumbNailImage;
    }

    public void setThumbNailImage(byte[] thumbNailImage) {
        this.thumbNailImage = thumbNailImage;
    }

    @Column(name="Terminal_Image")
    public byte[] getTerminalImage() {
        return this.terminalImage;
    }

    public void setTerminalImage(byte[] terminalImage) {
        this.terminalImage = terminalImage;
    }

    @Column(name="CreatedBy", length=50)
    public String getCreatedBy() {
        return this.createdBy;
    }

    public void setCreatedBy(String createdBy) {
        this.createdBy = createdBy;
    }

    @Column(name="CreatedOn", nullable=false, length=23)
    public Date getCreatedOn() {
        return this.createdOn;
    }

    public void setCreatedOn(Date createdOn) {
        this.createdOn = createdOn;
    }

    @Column(name="ModifiedBy", length=50)
    public String getModifiedBy() {
        return this.modifiedBy;
    }

    public void setModifiedBy(String modifiedBy) {
        this.modifiedBy = modifiedBy;
    }

    @Column(name="ModifiedOn", length=23)
    public Date getModifiedOn() {
        return this.modifiedOn;
    }

    public void setModifiedOn(Date modifiedOn) {
        this.modifiedOn = modifiedOn;
    }

    @Column(name="RFU1", length=100)
    public String getRfu1() {
        return this.rfu1;
    }

    public void setRfu1(String rfu1) {
        this.rfu1 = rfu1;
    }

    @Column(name="RFU2", length=100)
    public String getRfu2() {
        return this.rfu2;
    }

    public void setRfu2(String rfu2) {
        this.rfu2 = rfu2;
    }

    @Column(name="RFU3", length=100)
    public String getRfu3() {
        return this.rfu3;
    }

    public void setRfu3(String rfu3) {
        this.rfu3 = rfu3;
    }




}  

Kindly help me to resolve this issue

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

初吻给了烟 2024-11-03 13:14:54

您使用的是哪个版本的 Postgresql?您使用的是服务器版本 9 和 JDBC 驱动程序 8.4? (因为如果是这样的话: Hibernate 3.3.2GA 不正确地从 PostgreSQL 9.0 加载 bytea 数据,并且所有类型映射都是正确的

数据库中存储的实际值是多少?使用psql进行检查,并将前16个字节左右与预期值进行比较。由于它们是图像,您会期望它们以某种格式魔法开始 - “JFIF”、“GIF”、“PNG”、“II”/“MM”等。您需要能够确定数据是否已损坏保存时、加载时损坏或其他问题。在保存对象之前和加载之后转储图像数组的前几个字节,以与 psql 中的值进行比较。

Which version of Postgresql are you using? Are you using server version 9 and JDBC driver 8.4? (because if so: Hibernate 3.3.2GA improperly loads bytea data from PostgreSQL 9.0 and all type mappings are correct)

What is the actual value being stored in the database? Use psql to check, and compare the first 16 bytes or so with the expected values. Since they are images you would expect them to start with some format magic- "JFIF", "GIF", "PNG", "II"/"MM" etc. You need to be able to determine if the data is being corrupted when being saved, corrupted when being loaded or some other problem. Dump the first few bytes of the image array before saving the object and after loading to compare with the values from psql.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文