org.hibernate.HibernateException类的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(11.5k)|赞(0)|评价(0)|浏览(208)

本文整理了Java中org.hibernate.HibernateException类的一些代码示例,展示了HibernateException类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HibernateException类的具体详情如下:
包路径:org.hibernate.HibernateException
类名称:HibernateException

HibernateException介绍

[英]The base exception type for Hibernate exceptions.

Note that all java.sql.SQLException will be wrapped in some form of JDBCException.
[中]Hibernate异常的基本异常类型。
请注意,所有java语言都是。sql。SQLException将以某种形式的JDBCException进行包装。

代码示例

代码示例来源:origin: hibernate/hibernate-orm

final TransactionManager transactionManager = jtaPlatform.retrieveTransactionManager();
if ( transactionManager == null ) {
  throw new HibernateException( "No TransactionManagerLookup specified" );
  txn = transactionManager.getTransaction();
  if ( txn == null ) {
    throw new HibernateException( "Unable to locate current JTA transaction" );
  if ( !JtaStatusHelper.isActive( txn.getStatus() ) ) {
    throw new HibernateException( "Current transaction is not in progress" );
  throw new HibernateException( "Problem locating/validating JTA transaction", t );
    txn.registerSynchronization( buildCleanupSynch( txnIdentifier ) );
      currentSession.close();
    throw new HibernateException( "Unable to register cleanup Synchronization with TransactionManager" );

代码示例来源:origin: spring-projects/spring-framework

/**
 * Create a new HibernateSystemException,
 * wrapping an arbitrary HibernateException.
 * @param cause the HibernateException thrown
 */
public HibernateSystemException(@Nullable HibernateException cause) {
  super(cause != null ? cause.getMessage() : null, cause);
}

代码示例来源:origin: spring-projects/spring-framework

return new DataAccessResourceFailureException(ex.getMessage(), ex);
return new InvalidDataAccessResourceUsageException(ex.getMessage() + "; SQL [" + jdbcEx.getSQL() + "]", ex);
return new org.springframework.dao.QueryTimeoutException(ex.getMessage() + "; SQL [" + jdbcEx.getSQL() + "]", ex);
return new CannotAcquireLockException(ex.getMessage() + "; SQL [" + jdbcEx.getSQL() + "]", ex);
return new PessimisticLockingFailureException(ex.getMessage() + "; SQL [" + jdbcEx.getSQL() + "]", ex);
return new DataIntegrityViolationException(ex.getMessage()  + "; SQL [" + jdbcEx.getSQL() +
    "]; constraint [" + jdbcEx.getConstraintName() + "]", ex);
return new DataIntegrityViolationException(ex.getMessage() + "; SQL [" + jdbcEx.getSQL() + "]", ex);
return new IncorrectResultSizeDataAccessException(ex.getMessage(), 1, ex);
return new DuplicateKeyException(ex.getMessage(), ex);
return new DataIntegrityViolationException(ex.getMessage(), ex);
return new InvalidDataAccessApiUsageException(ex.getMessage(), ex);
return new InvalidDataAccessApiUsageException(ex.getMessage(), ex);
return new InvalidDataAccessApiUsageException(ex.getMessage(), ex);
if (ex.getCause() instanceof LockAcquisitionException) {
  return new CannotAcquireLockException(ex.getMessage(), ex.getCause());

代码示例来源:origin: org.ikasan/ikasan-connector-basefiletransfer

Session session = this.sessionFactory.openSession();
try
  Query query = session.createQuery(hibernateQuery.toString());
  query.setParameter(CLIENT_ID, clientId);
  query.setParameter(CREATED_DATE_TIME, cal.getTime().getTime());
  query.setMaxResults(maxRows);
  fileFilters = query.list();
  if (fileFilters != null)
      session.delete(fileFilter);
      session.flush();
  sb.append(hibernateQuery.toString());
  sb.append("].");
  logger.error(sb.toString() + " " + e.getMessage(), e);
  throw e;

代码示例来源:origin: Transitime/core

if (clause != null)
  hql += " " + clause;
Query query = session.createQuery(hql);
  query.setString("vehicleId", vehicleId);
query.setTimestamp("beginDate", beginTime);
query.setTimestamp("endDate", endTime);
} catch (HibernateException e) {
  Core.getLogger().error(e.getMessage(), e);
  return null;
} finally {
  session.close();

代码示例来源:origin: phenotips/phenotips

@Override
public void store(AuditEvent event)
{
  if (ACTION_IGNORED.contains(event.getAction())) {
    return;
  }
  Session session = this.sessionFactory.getSessionFactory().openSession();
  try {
    Transaction t = session.beginTransaction();
    t.begin();
    session.save(event);
    t.commit();
  } catch (HibernateException ex) {
    this.logger.error("Failed to save audit event [{}]: {}", event, ex.getMessage(), ex);
  } finally {
    session.close();
  }
}

代码示例来源:origin: Transitime/core

if (sqlClause != null)
  hql += " " + sqlClause;
Query query = session.createQuery(hql);
query.setTimestamp("beginDate", beginTime);
query.setTimestamp("endDate", endTime);
query.setFirstResult(firstResult);
query.setMaxResults(maxResults);
} catch (HibernateException e) {
  Core.getLogger().error(e.getMessage(), e);
  return null;
} finally {
  session.close();

代码示例来源:origin: stackoverflow.com

public void updateSessionStatus() {
   Session sess = factory.openSession();
   Transaction tx = null;
   try {
     tx = sess.beginTransaction();
     Criteria crit = sess.createCriteria(CollegeStudentsMaster.class);
     crit.add(Restrictions.eqProperty("academicYear", "courseYears"));
     // Here is updated code
     ScrollableResults items = crit.scroll();
     int count=0;
     while ( items.next() ) {
       CollegeStudentsMaster e = (CollegeStudentsMaster)items.get(0);
       e.setSessionStatus("G");
       sess.saveOrUpdate(e);
       if ( ++count % 100 == 0 ) {
         sess.flush();
         sess.clear();
       }
     }
     tx.commit();
   } catch (HibernateException asd) {
     if (tx != null) {
       tx.rollback();
     }
     log.debug(asd.getMessage());
   } finally {
     sess.close();
   }
 }

代码示例来源:origin: hibernate/hibernate-orm

transaction = session.beginTransaction();
  session.persist(parent);
  session.flush();
  parentId = parent.getId();
    transaction.rollback();
  fail(e.getMessage());
} finally {
  if (session != null) {
    transaction.rollback();
  fail(e.getMessage());
} finally {
  if (session != null) {
    transaction.rollback();
  fail(e.getMessage());
} finally {
  if (session != null) {

代码示例来源:origin: org.ikasan/ikasan-connector-basefiletransfer

FileFilter resultObject = null;
Session session = this.sessionFactory.openSession();
try
  Query query = session.createQuery(hibernateQuery.toString());
  query.setParameter(CLIENT_ID, qo.getClientId());
  if (filterOnFilename)
    query.setParameter(CRITERIA, qo.getCriteria());
    query.setParameter(LAST_MODIFIED, qo.getLastModified());
  query.setParameter(SIZE, qo.getSize());
  sb.append(hibernateQuery.toString());
  sb.append("]."); //$NON-NLS-1$
  logger.error(sb.toString() + " " + e.getMessage(), e); //$NON-NLS-1$
  throw e;
  if (session.isOpen())
    session.close();

代码示例来源:origin: org.sakaiproject.kernel/sakai-kernel-impl

@Transactional(readOnly = true)
public List<MessageBundleProperty> getModifiedProperties(int sortOrder, int sortField, int startingIndex, int pageSize) {
  String orderBy = "asc";
  if (sortOrder == SORT_ORDER_DESCENDING) {
    orderBy = "desc";
  }
  String sortFieldName = "id";
  if (sortField == SORT_FIELD_MODULE) {
    sortFieldName = "moduleName";
  }
  if (sortField == SORT_FIELD_PROPERTY) {
    sortFieldName = "propertyName";
  }
  if (sortField == SORT_FIELD_LOCALE) {
    sortFieldName = "locale";
  }
  if (sortField == SORT_FIELD_BASENAME) {
    sortFieldName = "baseName";
  }
  org.hibernate.Query query = null;
  String queryString = "from MessageBundleProperty where value != null order by " + sortFieldName + " " + orderBy;
  try {
    query = getSessionFactory().getCurrentSession().createQuery(queryString);
    query.setFirstResult(startingIndex);
    query.setMaxResults(pageSize);
    return query.list();
  } catch (HibernateException e) {
    throw new RuntimeException(e.getMessage(), e);
  }
}

代码示例来源:origin: Transitime/core

Session session = sessionFactory.openSession();
Query query = session.createQuery(hql);
query.setInteger("configRev", configRev);
  List<TravelTimesForStopPath> travelTimes = query.list();
  return travelTimes;
} catch (HibernateException e) {
  logger.error(e.getMessage(), e);
  return null;
} finally {
  session.close();

代码示例来源:origin: com.opensymphony.propertyset.providers/hibernate5

public void remove(final String entityName, final Long entityId, final String key)
  {
    try
    {
      final Session session = sessionFactory.getCurrentSession();
      session.delete(HibernatePropertySetDAOUtils.getItem(session, entityName, entityId, key));
      session.flush();
    }
    catch (final HibernateException e)
    {
      throw new PropertyException("Could not remove key '" + key + "': " + e.getMessage());
    }
  }
}

代码示例来源:origin: org.sakaiproject.samigo/samigo-services

Session session = null;
try {
  session = getSessionFactory().openSession();
  String query0 = "select LOCATION from SAM_MEDIA_T where MEDIAID = :id";
  mediaLocation = (String) session.createSQLQuery(query0).setLong("id", mediaId).uniqueResult();
  log.debug("****mediaLocation=" + mediaLocation);
  session.createSQLQuery(query).setLong("id", mediaId).executeUpdate();
} catch (HibernateException e) {
  log.warn(e.getMessage());
} finally {
  if (session != null) {
    try {
      session.flush();
      session.close();
    } catch (Exception e1) {

代码示例来源:origin: org.nuiton.topia/topia-persistence

protected void rollback0(boolean beginAfterRollback) {
  try {
    Session hibernateSession = hibernateSupport.getHibernateSession();
    Transaction transaction = hibernateSession.getTransaction();
    hibernateSession.clear();
    transaction.rollback();
    hibernateSession.close();
    sessionRegistry.unregister(hibernateSession);
    if (beginAfterRollback) {
      // it's very important to change the session after rollback
      // otherwise there are many error during next Entity's modification
      hibernateSession = hibernateSupport.getHibernateFactory().openSession();
      hibernateSupport.setHibernateSession(hibernateSession);
      hibernateSession.setFlushMode(FlushMode.MANUAL);
      sessionRegistry.register(hibernateSession, this);
      hibernateSession.beginTransaction();
    }
    getTopiaFiresSupport().fireOnPostRollback(this);
  } catch (HibernateException eee) {
    String message = String.format("An error occurred during rollback operation: %1$s", eee.getMessage());
    throw new TopiaException(message, eee);
  }
}

代码示例来源:origin: hibernate/hibernate-orm

@Test
public void testIllegalMixedTransformerQueries() {
  Session session = openSession();
  Transaction t = session.beginTransaction();
  try {
    getSelectNewQuery( session ).setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP).list();
    fail("'select new' together with a resulttransformer should result in error!");
    getSelectNewQuery( session ).setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP).iterate();
    fail("'select new' together with a resulttransformer should result in error!");
    assertTrue(he.getMessage().indexOf("ResultTransformer")==0);
    assertTrue(he.getMessage().indexOf("ResultTransformer")==0);
  session.close();

代码示例来源:origin: com.opensymphony.propertyset.providers/hibernate4

public void remove(String entityName, Long entityId, String key)
  {
    Session session = null;

    try
    {
      session = this.sessionFactory.openSession();
      session.delete(HibernatePropertySetDAOUtils.getItem(session, entityName, entityId, key));
      session.flush();
    }
    catch (HibernateException e)
    {
      throw new PropertyException("Could not remove key '" + key + "': " + e.getMessage());
    }
    finally
    {
      try
      {
        if (session != null)
        {
          session.close();
        }
      }
      catch (Exception e)
      {
      }
    }
  }
}

代码示例来源:origin: Transitime/core

try {
  Transaction tx = session.beginTransaction();
  int numUpdates = session.createQuery(hql).executeUpdate();
} catch (HibernateException e) {
  logger.error("Could not delete DbTest objects. {}. {}", 
      e.getCause().getMessage(),
      e.getMessage());
  throw e;
} finally {
  session.close();

代码示例来源:origin: com.opensymphony.propertyset.providers/hibernate5

public void setImpl(final PropertySetItem item, final boolean isUpdate)
{
  try
  {
    final Session session = sessionFactory.getCurrentSession();
    if (isUpdate)
    {
      session.update(item);
    }
    else
    {
      session.save(item);
    }
    session.flush();
  }
  catch (final HibernateException he)
  {
    throw new PropertyException("Could not save key '" + item.getKey() + "':" + he.getMessage());
  }
}

代码示例来源:origin: Transitime/core

Query query = session.createQuery(hql);
try {
  List<DbTest> dbTests = query.list();
  return dbTests;
} catch (HibernateException e) {
  logger.error("Could not get DbTest object. {}. {}", 
      e.getCause().getMessage(), e.getMessage());
  throw e;
} finally {
  session.close();

相关文章