I am developing a web application using Struts 2.1.2 and Hibernate 3.2.6.GA. I have an entity, User, which I have mapped to a table USERS in the DB using Hibernate. I want to have an image associated with this entity, which I plan to store as a BLOB in the DB. I also want to display the image on a webpage along with other attributes of the User.
The solution I could think of was to have a table IMAGES(ID, IMAGE) where IMAGE is a BLOB column. USERS will have an FK column called IMAGEID, which points to the IMAGES table. I will then map a property on User entity, called 'imageId' mapped to this IMAGEID as a Long. When rendering the page with a JSP, I would add images as <img src="images.action?id=1"/> etc, and have an Action which reads the image and streams the content to the browser, with the headers set to cache the image for a long time.
Will this work? Is there a better approach for rendering images stored in a DB? Is storing such images in the DB the right approach in the first place?