• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Upload files in EJB?

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am implementing a web application (an ecommerce website) . I use EJB for the app logic. Now I am facing a dilemma.

The app use JSF for presentation. Users will upload products they want to sell to the website. Each product can have many images. So now I have 2 Entities: Product and ProductImage. The images of their products will be stored on Amazon S3. Here is the flow:

1. User must fill the form (information of the product including product name, price, description, etc ...). Upload images and click submit.
2. Since the Product table in database uses an automatic incremented column as Primary key and I need that key to make image key, I must save product information to database first, then retrieve it from database and then call product.getId() to get the key. Then use that key as a part of the image key to upload that images to Amazon S3.
3. Use the keys of the images to make ProductImage entities. Call product.setImages(List<ProductImage> images) to update the product.
4. Use JPA to save the product to database.

I have two questions:
1. When use upload images, should I use just JSF for that or should I use EJB?
2. Is there any better way (algorithm) to solve the problem above? What's your approach?

Thank you!
 
Bartender
Posts: 3648
16
Android Mac OS X Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For upload files, most likely use JSF to get the "uploaded" file object then you can call EJB or another thread or whatever to actually write that file content to disk.

The algorithm you have seems fine, just make sure it is a single (all or nothing) transaction.
 
reply
    Bookmark Topic Watch Topic
  • New Topic