List of usage examples for org.hibernate HibernateException HibernateException
public HibernateException(Throwable cause)
From source file:org.apache.ode.daohib.JotmTransactionFactory.java
License:Open Source License
/** * {@inheritDoc}// w w w .ja va2 s. c o m */ public Transaction createTransaction(JDBCContext jdbcContext, Context transactionContext) throws HibernateException { /* * JTA TransactionManager returns a JTA transaction. We need a user transaction to use * hibernate's JTATransactionFactory. */ // UserTransaction ut = getUserTransaction(); UserTransaction ut; try { ut = new UserTransaction() { javax.transaction.Transaction transaction = txManager.getTransaction(); public void begin() throws NotSupportedException, SystemException { // TODO Auto-generated method stub } public void commit() throws HeuristicMixedException, HeuristicRollbackException, IllegalStateException, RollbackException, SecurityException, SystemException { transaction.commit(); } public int getStatus() throws SystemException { // TODO Auto-generated method stub return transaction.getStatus(); } public void rollback() throws IllegalStateException, SecurityException, SystemException { // TODO Auto-generated method stub transaction.rollback(); } public void setRollbackOnly() throws IllegalStateException, SystemException { // TODO Auto-generated method stub transaction.setRollbackOnly(); } public void setTransactionTimeout(int i) throws SystemException { // TODO Auto-generated method stub } }; } catch (SystemException e) { throw new HibernateException(e); } return new JotmTransaction(ut, jdbcContext, transactionContext); }
From source file:org.apache.tapestry5.internal.hibernate.EntityPersistentFieldStrategyTest.java
License:Apache License
public void not_an_entity() { String nonEntity = "foo"; Session session = newMock(Session.class); EntityPersistentFieldStrategy strategy = new EntityPersistentFieldStrategy(session, null); expect(session.contains(nonEntity)).andReturn(true); expect(session.getEntityName(nonEntity)).andThrow(new HibernateException("error")); replay();//from ww w . j a v a 2s . c om try { strategy.postChange("pageName", "", "fieldName", nonEntity); unreachable(); } catch (IllegalArgumentException ex) { assertEquals(ex.getMessage(), "Failed persisting an entity in the session. entity: foo"); } verify(); }