I have simple Image object which has a binary attribute. I read a file and set the binary attribute of the Image object. When I try to call
Code:
Image imageObject = EntityManager.merge( imageObject );
The image gets stored in the database table but its binary data is nulled. I want to call merge because it returns the new merged object. Now if I run the following code the binary data gets stored and I obtain the new instance of the persist object.
Code:
EntityManager.persist( imageObject );
EntityManager.refresh( imageObject);
Why would this work with persist but not with merge?
Here is my Image class:
Code:
import java.sql.Blob;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
@Entity
public class Image {
private Integer width;
private Integer height;
private Blob bin;
private Integer fileSize;
public Image() {}
public void setWidth(Integer width) {
this.width = width;
}
public Integer getWidth() {
return width;
}
public void setHeight(Integer height) {
this.height = height;
}
public Integer getHeight() {
return height;
}
public void setBin(Blob binary) {
this.bin = binary;
}
@Basic(fetch=FetchType.LAZY)
@Column(columnDefinition="MEDIUMBLOB")
public Blob getBin() {
return bin;
}
public void setFileSize(Integer fileSize) {
this.fileSize = fileSize;
}
public Integer getFileSize() {
return fileSize;
}
}