aspose file tools*
The moose likes EJB and other Java EE Technologies and the fly likes Upload files in EJB? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Upload files in EJB?" Watch "Upload files in EJB?" New topic
Author

Upload files in EJB?

Long Hoang
Greenhorn

Joined: Mar 09, 2011
Posts: 2
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

Joined: Sep 13, 2007
Posts: 2503
    
    8

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.

K. Tsang JavaRanch SCJP5 SCJD/OCM-JD OCPJP7 OCPWCD5 OCPBCD5
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Upload files in EJB?