I'm running into performance issues when using Hibernate from a session bean. I've heard that Hibernate has good performance so I assume I'm doing something wrong.
My session bean has course-grained methods that are each intended to be run as a single transaction.
Here's a simple example method:
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public int createOrder(int customerId) throws BookStoreException {
Session session = null;
try {
session = sessionFactory.openSession();
Customer cust = (Customer) session.load(Customer.class, customerId);
CustomerOrder o = new CustomerOrder();
o.setCustomer(cust);
o.setTotalAmount(ZERO);
session.save(o);
return o.getId();
} catch (Exception e) {
throw new BookStoreException(e);
}
finally {
if (session != null) {
session.close();
}
}
}
Is this a correct use of sessions / transactions? Am I doing something fundamentally wrong here?
I'm running the bean in JBoss 4.2.1 GA against a MySQL DataSource.
Thanks,
Andy Grove.