spring - Loading Image into byte array in entity bean -
i using spring data jpa , hibernate retrieve entities db table. 1 of entity fields path image located on filesystem. possible load image byte array entity? e.g
@entity @table(name="users") public class user { @id @generatedvalue int id; string name; string picturename; @transient byte[] image; // other properties public void setpicturename(string picturename) { string path="d:\\images\\"; file f = new file(path + picturename); this.image = new byte[(int)f.length()]; fileutility.tobytearray(f,this.image); //custom class this.picture = picture; } //other stuff }
i tried jpa byte array image field comes null while else fine.
yes, possible, have map whatever column has picture name hibernate can populate it.
thus, if have column called "picture_name" entity should have:
@column(name="picture_name") private string picturename;
then, when hibernate loads entity, call setpicturename
method , run code load file byte array.
Comments
Post a Comment