Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Upload files in EJB?

 
Long Hoang
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • 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!
 
K. Tsang
Bartender
Posts: 3457
14
Android Java
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic