I would suggest using a MySQL type of BLOB or MEDIUMBLOB (depending on whether your images are all smaller than 64k or all smaller than 16M), a Java type of byte[], marking the column as lazy, and interpreting the image data at a higher level (say in your GUI code, using
ImageIcon.ImageIcon(byte[]) ).
Your .hbm.xml file would have a section like:
Code:
<class name="person" table="person" >
...
<property name="photo" type="blob" lazy="true" access="field" />
...
Your data-model class would expose the image data, but is could also have a helper method to create a renderable version of the image:
Code:
public class Person {
...
private byte[] photo;
...
public Icon loadPhoto() {
if (photo != null)
return new ImageIcon(photo);
else
return new ImageIcon(Person.class.getResource("noface.png"));
}
As far as saving the image ... you don't say where it's coming from: the local filesystem? Uploaded to a web application? Generated in-memory (say with
WritableRenderedImage)?