*/
public void createOrder(Session session, Random random) {
session.currentTransaction().begin();
// get an order number
int orderid = getNextOrderId();
Order order = session.newInstance(Order.class);
order.setId(orderid);
// get a random customer number
int customerId = random .nextInt(nextCustomerId);
order.setCustomerId(customerId);
order.setDescription("Order " + orderid + " for Customer " + customerId);
Double orderValue = 0.0d;
// now create some order lines
int numberOfOrderLines = random.nextInt(maximumOrderLinesPerOrder);
for (int i = 0; i < numberOfOrderLines; ++i) {
int orderLineNumber = getNextOrderLineId();
OrderLine orderLine = session.newInstance(OrderLine.class);
orderLine.setId(orderLineNumber);
orderLine.setOrderId(orderid);
long quantity = random.nextInt(maximumQuantityPerOrderLine);
orderLine.setQuantity(quantity);
float unitPrice = ((float)random.nextInt(maximumUnitPrice)) / 4;
orderLine.setUnitPrice(unitPrice);
double orderLineValue = unitPrice * quantity;
orderValue += orderLineValue;
if (getDebug()) System.out.println("For order " + orderid + " orderline " + orderLineNumber +
" order line value " + orderLineValue + " order value " + orderValue);
orderLine.setTotalValue(orderLineValue);
addOrderLine(orderLine);
session.persist(orderLine);
}
order.setValue(orderValue);
session.persist(order);
session.currentTransaction().commit();
addOrder(order);
}