I am storing users data in a table along with pictures using JPA. I have successfully stored the images in data base. I have to display the data on a JSF page in data table along with the pictures. Now I am facing the problem of how to display the pictures. When I retrieve the data, all the records are fetched along with the pictures in form of byte arrays. I am only stuck on how to display the images.
I found several programs on Internet which used to pass Id of the image to a servlet which will retrieve the image and process it and send as a response which means for 10 pics, there will be 10 seperate full cycle requests to database when I am already having all the pics loaded to memory. I don't want to make a separate request for each image of each record. Reason being its a distributed application. Every call means a remote call and serialization and all that other stuff.
Well, I have two servers A and B. The core application is installed on server B. HTTP requests are received to server A which then queries server B and returns result. So there will be remote calls from server A to server B.
Now when serve A requests from server B all the list of users, server B will return the list along with the Images. When server A all the records in hand, I want that server A should make the images and return it as HTTP response. Not like that it make separate remote request again for each image again from server B.
An HTTP request can only be for a single page, or for a single image. Once the images arrive at A from B (as the result of a page being requested), you need to store them on A somehow, either on disk or in memory. Then you need to make sure that the page being sent back from A to the client contains image URLs that point to A in a way so that A can be sure that the image is present there (and doesn't need to be retrieved from B).
Yeah. Its the only way. Now I create temporary images on server A when I get the list, and send its paths in response. But now I have another problem.
As according to JPA recommendations, I am using the @Lob on the ''image' field which is of type byte and fetch type is lazy.
According to this, when I query, the images must not be loaded into memory as its Lazy fetch but still they are loaded.
I am using Hibernate as persistence provider. What can be the problem??
Hey! You're stepping on my hand! Help me tiny ad!
Free, earth friendly heat - from the CodeRanch trailboss