Dearl all,
I'm newbie of hibernate and I'm trying to use it with derby in my javafx application.
I 've an issue only with blob type.
Here is my entity (I use annotations)
Code:
@Entity
@Table(name = "allegato")
public class Allegato extends org.jfxtras.lang.XObject implements java.io.Serializable{
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Column(name = "ID_ALLEGATO")
private long idAllegato;
@Column(name = "ID_DIAGNOSI")
private long idDiagnosi;
@Column(name="BLOB", length=Integer.MAX_VALUE - 1)
@Basic(fetch=FetchType.LAZY)
private Blob blob;
public long getIdAllegato() {
return idAllegato;
}
public void setIdAllegato(long idAllegato) {
this.idAllegato = idAllegato;
}
public long getIdDiagnosi() {
return idDiagnosi;
}
public void setIdDiagnosi(long idDiagnosi) {
this.idDiagnosi = idDiagnosi;
}
public Blob getBlob() {
return blob;
}
public void setBlob(Blob blob) {
this.blob = blob;
}}
I get file from path and put it into blob field in this way:
Code:
File source = new File(allegati[j]);
byte[] bFile = new byte[(int) source.length()];
try {
FileInputStream fileInputStream = new FileInputStream(source.getAbsolutePath());
//convert file into array of bytes
fileInputStream.read(bFile);
Blob cBlob = Hibernate.createBlob(fileInputStream, (int) source.length());
cAllegato.setBlob(cBlob);
fileInputStream.close();
I've got this exception
Code:
GRAVE: A truncation error was encountered trying to shrink BLOB '(Binary data value not displayed)' to length 255.
Exception occurred during event dispatching:
ortholab2.dao.DataAccessLayerException: org.hibernate.exception.DataException: could not insert: [ortholab2.entity.Allegato]
Please help me,
Thanks ,
Regards