Web hosting asp - CHAPTER 10 Transactions and concurrency exceptions thrown by
CHAPTER 10 Transactions and concurrency exceptions thrown by Hibernate are fatal. In many cases, the best a developer can do in this situation is to clean up, display an error message, and exit the application. Therefore, starting with Hibernate 3.x, all exceptions thrown by Hibernate are subtypes of the unchecked Runtime- Exception, which is usually handled in a single location in an application. This also makes any Hibernate template or wrapper API obsolete. First, even though we admit that you wouldn t write your application code with dozens (or hundreds) of try/catch blocks, the example we showed isn t complete. This is an example of the standard idiom for a Hibernate unit of work with a database transaction that contains real exception handling: Session session = null; Transaction tx = null; try { session = sessionFactory.openSession(); tx = session.beginTransaction(); tx.setTimeout(5); concludeAuction(session); tx.commit(); } catch (RuntimeException ex) { try { tx.rollback(); } catch (RuntimeException rbEx) { log.error(”Couldn t roll back transaction”, rbEx); } throw ex; } finally { session.close(); } Any Hibernate operation, including flushing the persistence context, can throw a RuntimeException. Even rolling back a transaction can throw an exception! You want to catch this exception and log it; otherwise, the original exception that led to the rollback is swallowed. An optional method call in the example is setTimeout(), which takes the number of seconds a transaction is allowed to run. However, real monitored transactions aren t available in a Java SE environment. The best Hibernate can do if you run this code outside of an application server (that is, without a transaction manager) is to set the number of seconds the driver will wait for a Prepared- Statement to execute (Hibernate exclusively uses prepared statements). If the limit is exceeded, an SQLException is thrown.
If you are searching for cheap webhost for your web application, please visit MySQL5 Web Hosting services.