• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Rob Spoor
  • Devaka Cooray
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Jj Roberts
  • Al Hobbs
  • Piet Souris

Retreiving image through JPA and displaying it

 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

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.

Is there any possible solution to this.

Regards
 
Rancher
Posts: 43027
76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I don't want to make a separate request for each image of each record.


There's no way around that if we're talking about an HTML/HTTP client.

Reason being its a distributed application. Every call means a remote call and serialization and all that other stuff.


What do you mean by "serialization" in this context? You mentioned JSF, which implies HTTP/HTML; if you're using something else, then TellTheDetails.
 
Shayan Shah
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ulf Dittmer
Rancher
Posts: 43027
76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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).
 
Shayan Shah
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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??

Thanks
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic