1 Reply Latest reply on Dec 8, 2006 5:11 AM by aidan_b5

    Blob reading causing memory leak?

    aidan_b5

      I have three entity beans; one Audit contains many AuditImage, one AuditImage contains one AuditLargeImage .

      Audit to AuditImage is eagerly loaded, AuditImage to AuditLargeImage is lazily loaded.

      I can sucessfully upload images to the database (MySQL) but when I load (manager.find) the Audit, the servers memory usage jumps to over 1GB! Despite total image size being only 5mb

      @Entity(name = "Audit")
      public class Audit {
      
      private Set<AuditImage> image;
      
       @OneToMany(cascade = {CascadeType.ALL}, fetch = FetchType.EAGER)
       public Set<AuditImage> getImages() {
       if (image == null)
       image = new HashSet<AuditImage>();
       return image;
       }
      
       public void setImages(Set<AuditImage> image) {
       this.image = image;
       }
      }
      
      }
      


      @Entity
      @Table(name = "auditimage")
      public class AuditImage {
      
       private int id;
      
       @Id
       @GeneratedValue(strategy = GenerationType.AUTO)
       public int getId() {
       return id;
       }
      
       public void setId(int id) {
       this.id = id;
       }
      
       private String imageName;
      
       private byte[] imageThumb;
      
      private AuditLargeImage imageLarge;
      
       @Lob
       @Column(columnDefinition = "BLOB")
       public byte[] getImageThumb() {
       return imageThumb;
       }
      
       public void setImageThumb(byte[] imageThumb) {
       this.imageThumb = imageThumb;
       }
      
       public String getImageName() {
       return imageName;
       }
      
       public void setImageName(String imageName) {
       this.imageName = imageName;
       }
      
      @OneToOne(cascade = {CascadeType.ALL}, fetch = FetchType.LAZY)
       public AuditLargeImage getImageLarge() {
       return imageLarge;
       }
      
       public void setImageLarge(AuditLargeImage imageLarge) {
       this.imageLarge = imageLarge;
       }
      }
      


      @Entity
      public class AuditLargeImage {
       private int id;
      
       @Id
       @GeneratedValue(strategy = GenerationType.AUTO)
       public int getId() {
       return id;
       }
      
       public void setId(int id) {
       this.id = id;
       }
      
       private byte[] imageFull;
      
       @Lob
       @Column(columnDefinition = "MEDIUMBLOB")
       public byte[] getImageFull() {
       return imageFull;
       }
      
       public void setImageFull(byte[] imageFull) {
       this.imageFull = imageFull;
       }
      
      }
      
      


      Am currently using JBOSS 4.05 GA, Hibernate 3.2.1 with the latest mysql jdbc connector (5.0.4).

      Even if I remove all references to AuditLargeImage (as in disregard it from the test) I still have the same problem...

      Your comments appreciated. Thanks

        • 1. Re: Blob reading causing memory leak?
          aidan_b5

          Ok found two problems:

          Lazy OneToOne mapping has to have 'optional=false' in order to work

          but more seriously;

          
          manager.find(Audit.class, id);
          
          


          Causes an infinite loop...........replacing it with a select statement solves the problem but that isn't great.

          Does anyone know anything about this?