Web hosting domains - CHAPTER 10 Transactions and concurrency Exceptions thrown by
CHAPTER 10 Transactions and concurrency Exceptions thrown by JPA are subtypes of RuntimeException. Any exception invalidates the current persistence context, and you aren t allowed to continue working with the EntityManager once an exception has been thrown. Therefore, all the strategies we discussed for Hibernate exception handling also apply to Java Persistence exception handling. In addition, the following rules apply: Any exception thrown by any method of the EntityManager interfaces triggers an automatic rollback of the current transaction. Any exception thrown by any method of the javax.persistence.Query interface triggers an automatic rollback of the current transaction, except for NoResultException and NonUniqueResultException. So, the previous code example that catches all exceptions also executes a rollback for these exceptions. Note that JPA doesn t offer fine-grained SQL exception types. The most common exception is javax.persistence.PersistenceException. All other exceptions thrown are subtypes of PersistenceException, and you should consider them all fatal except NoResultException and NonUniqueResultException. However, you may call getCause() on any exception thrown by JPA and find a wrapped native Hibernate exception, including the fine-grained SQL exception types. If you use Java Persistence inside an application server or in an environment that at least provides JTA (see our earlier discussions for Hibernate), you call the JTA interfaces for programmatic transaction demarcation. The EntityTransaction interface is available only for resource-local transactions. JTA transactions with Java Persistence If your Java Persistence code is deployed in an environment where JTA is available, and you want to use JTA system transactions, you need to call the JTA UserTransaction interface to control transaction boundaries programmatically: UserTransaction utx = (UserTransaction) new InitialContext() .lookup(”java:comp/UserTransaction”); EntityManager em = null; try { utx.begin(); em = emf.createEntityManager(); concludeAuction(em); utx.commit(); } catch (RuntimeException ex) { try {
You want to have a cheap webhost for your apache application, then check apache web hosting services.