/** * {@inheritDoc} */ //FIXME should we remove all calls to this method and use convert(RuntimeException) ? public RuntimeException convert(HibernateException e) { return convert( e, null ); }
/** * {@inheritDoc} */ public void throwPersistenceException(HibernateException e) { throw convert( e ); }
public RuntimeException convert(RuntimeException e) { RuntimeException result = e; if ( e instanceof HibernateException ) { result = convert( ( HibernateException ) e ); } else { markAsRollback(); } return result; }
@Override public RuntimeException mapManagedFlushFailure(String message, RuntimeException failure) { if ( HibernateException.class.isInstance( failure ) ) { throw convert( failure ); } if ( PersistenceException.class.isInstance( failure ) ) { throw failure; } throw new PersistenceException( message, failure ); } }
public void clear() { try { getSession().clear(); } catch ( HibernateException he ) { throw convert( he ); } }
public void remove(Object entity) { checkTransactionNeeded(); try { getSession().delete( entity ); } catch ( MappingException e ) { throw new IllegalArgumentException( e.getMessage(), e ); } catch ( RuntimeException e ) { //including HibernateException throw convert( e ); } }
public void detach(Object entity) { try { getSession().evict( entity ); } catch ( HibernateException he ) { throw convert( he ); } }
public Query createQuery(String jpaqlString) { try { return applyProperties( new QueryImpl<Object>( getSession().createQuery( jpaqlString ), this ) ); } catch ( HibernateException he ) { throw convert( he ); } }
public void flush() { if ( !isTransactionInProgress() ) { throw new TransactionRequiredException( "no transaction is in progress" ); } try { getSession().flush(); } catch ( RuntimeException e ) { throw convert( e ); } }
public Query createNamedQuery(String name) { try { org.hibernate.Query namedQuery = getSession().getNamedQuery( name ); try { return new QueryImpl( namedQuery, this ); } catch ( HibernateException he ) { throw convert( he ); } } catch ( MappingException e ) { throw new IllegalArgumentException( "Named query not found: " + name ); } }
@SuppressWarnings("unchecked") public <T> T getReference(Class<T> entityClass, Object primaryKey) { try { return ( T ) getSession().load( entityClass, ( Serializable ) primaryKey ); } catch ( MappingException e ) { throw new IllegalArgumentException( e.getMessage(), e ); } catch ( TypeMismatchException e ) { throw new IllegalArgumentException( e.getMessage(), e ); } catch ( ClassCastException e ) { throw new IllegalArgumentException( e.getMessage(), e ); } catch ( HibernateException he ) { throw convert( he ); } }
public Query createNativeQuery(String sqlString) { try { SQLQuery q = getSession().createSQLQuery( sqlString ); return new QueryImpl( q, this ); } catch ( HibernateException he ) { throw convert( he ); } }
public Query createNativeQuery(String sqlString, Class resultClass) { try { SQLQuery q = getSession().createSQLQuery( sqlString ); q.addEntity( "alias1", resultClass.getName(), LockMode.READ ); return new QueryImpl( q, this ); } catch ( HibernateException he ) { throw convert( he ); } }
public void persist(Object entity) { checkTransactionNeeded(); try { getSession().persist( entity ); } catch ( MappingException e ) { throw new IllegalArgumentException( e.getMessage() ); } catch ( RuntimeException e ) { throw convert( e ); } }
@SuppressWarnings("unchecked") public <A> A merge(A entity) { checkTransactionNeeded(); try { return ( A ) getSession().merge( entity ); } catch ( ObjectDeletedException sse ) { throw new IllegalArgumentException( sse ); } catch ( MappingException e ) { throw new IllegalArgumentException( e.getMessage(), e ); } catch ( RuntimeException e ) { //including HibernateException throw convert( e ); } }
public boolean contains(Object entity) { try { if ( entity != null && !( entity instanceof HibernateProxy ) && getSession().getSessionFactory().getClassMetadata( entity.getClass() ) == null ) { throw new IllegalArgumentException( "Not an entity:" + entity.getClass() ); } return getSession().contains( entity ); } catch ( MappingException e ) { throw new IllegalArgumentException( e.getMessage(), e ); } catch ( HibernateException he ) { throw convert( he ); } }
public Query createNativeQuery(String sqlString, String resultSetMapping) { try { SQLQuery q = getSession().createSQLQuery( sqlString ); q.setResultSetMapping( resultSetMapping ); return new QueryImpl( q, this ); } catch ( HibernateException he ) { throw convert( he ); } }
public void lock(Object entity, LockModeType lockModeType, Map<String, Object> properties) { LockOptions lockOptions = null; if ( !isTransactionInProgress() ) { throw new TransactionRequiredException( "no transaction is in progress" ); } try { if ( !contains( entity ) ) { throw new IllegalArgumentException( "entity not in the persistence context" ); } getSession().buildLockRequest( ( lockOptions = getLockRequest( lockModeType, properties ) ) ) .lock( entity ); } catch ( HibernateException he ) { throw convert( he, lockOptions ); } }
public <T> TypedQuery<T> createQuery( String jpaqlString, Class<T> resultClass, Selection selection, Options options) { try { org.hibernate.Query hqlQuery = getSession().createQuery( jpaqlString ); if ( options.getValueHandlers() == null ) { options.getResultMetadataValidator().validate( hqlQuery.getReturnTypes() ); } // determine if we need a result transformer List tupleElements = Tuple.class.equals( resultClass ) ? ( ( CompoundSelectionImpl<Tuple> ) selection ).getCompoundSelectionItems() : null; if ( options.getValueHandlers() != null || tupleElements != null ) { hqlQuery.setResultTransformer( new CriteriaQueryTransformer( options.getValueHandlers(), tupleElements ) ); } return new QueryImpl<T>( hqlQuery, this, options.getNamedParameterExplicitTypes() ); } catch ( HibernateException he ) { throw convert( he ); } }
public void refresh(Object entity, LockModeType lockModeType, Map<String, Object> properties) { checkTransactionNeeded(); CacheMode previousCacheMode = getSession().getCacheMode(); CacheMode localCacheMode = determineAppropriateLocalCacheMode( properties ); LockOptions lockOptions = null; try { getSession().setCacheMode( localCacheMode ); if ( !getSession().contains( entity ) ) { throw new IllegalArgumentException( "Entity not managed" ); } if ( lockModeType != null ) { getSession().refresh( entity, ( lockOptions = getLockRequest( lockModeType, properties ) ) ); } else { getSession().refresh( entity ); } } catch ( MappingException e ) { throw new IllegalArgumentException( e.getMessage(), e ); } catch ( HibernateException he ) { throw convert( he, lockOptions ); } finally { getSession().setCacheMode( previousCacheMode ); } }