| All,
 I am putting together a simple shopping cart application.  As a business requirement, customers cannot order more products than are currently in stock (No Back Ordering).
 
 This application has an Order object which contains LineItem objects.  Each line item references a Product.  Each of these objects has its own underlying table.  The "Product" table contains product information as well as the products quantity.  The LineItem object/table contains the quantity of the product that gets ordered by the customer.
 
 Where/when should the remaining inventory get calculated?  If I use hibernate, it sounds like I would have to retrieve all of the lineItems for a particular product and sum up the ordered quantities in each lineItem and subtract this number from the products quantity to determine the number available.  Does this sound right?  Is there a better way to do this?
 
 Regards,
 
 Joshua
 
 
 |