No mapeamento
@Column(name="conteudo")
//@Transient // será atualizado manualmente por problemas no uso do drive jdbc oracle com hibernate em campos blob
private byte[] conteudoRaw;
//Método que transforma File em Bytespublicstaticbyte[]getBytesFromFile(Filefile)throwsIOException{InputStreamis=newFileInputStream(file);
// Get the size of the filelonglength=file.length();// You cannot create an array using a long type.// It needs to be an int type.// Before converting to an int type, check// to ensure that file is not larger than Integer.MAX_VALUE.if(length>Integer.MAX_VALUE){// File is too large}// Create the byte array to hold the databyte[]bytes=newbyte[(int)length];// Read in the bytesintoffset=0;intnumRead=0;while(offset<bytes.length&&(numRead=is.read(bytes,offset,bytes.length-offset))>=0){offset+=numRead;}// Ensure all the bytes have been read inif(offset<bytes.length){thrownewIOException("Could not completely read file "+file.getName());}// Close the input stream and return bytesis.close();returnbytes;}