Search in sources :

Example 81 with HibernateException

use of org.hibernate.HibernateException in project hibernate-orm by hibernate.

the class ClassLoaderServiceImplTest method testStoppableClassLoaderService.

/**
     * HHH-8363 discovered multiple leaks within CLS.  Most notably, it wasn't getting GC'd due to holding
     * references to ServiceLoaders.  Ensure that the addition of Stoppable functionality cleans up properly.
     * 
     * TODO: Is there a way to test that the ServiceLoader was actually reset?
     */
@Test
@TestForIssue(jiraKey = "HHH-8363")
public void testStoppableClassLoaderService() {
    final BootstrapServiceRegistryBuilder bootstrapBuilder = new BootstrapServiceRegistryBuilder();
    bootstrapBuilder.applyClassLoader(new TestClassLoader());
    final ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder(bootstrapBuilder.build()).build();
    final ClassLoaderService classLoaderService = serviceRegistry.getService(ClassLoaderService.class);
    TestIntegrator testIntegrator1 = findTestIntegrator(classLoaderService);
    assertNotNull(testIntegrator1);
    TestIntegrator testIntegrator2 = findTestIntegrator(classLoaderService);
    assertNotNull(testIntegrator2);
    assertSame(testIntegrator1, testIntegrator2);
    StandardServiceRegistryBuilder.destroy(serviceRegistry);
    try {
        findTestIntegrator(classLoaderService);
        Assert.fail("Should have thrown an HibernateException -- the ClassLoaderService instance was closed.");
    } catch (HibernateException e) {
        String message = e.getMessage();
        Assert.assertEquals("HHH000469: The ClassLoaderService can not be reused. This instance was stopped already.", message);
    }
}
Also used : BootstrapServiceRegistryBuilder(org.hibernate.boot.registry.BootstrapServiceRegistryBuilder) StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) HibernateException(org.hibernate.HibernateException) ServiceRegistry(org.hibernate.service.ServiceRegistry) ClassLoaderService(org.hibernate.boot.registry.classloading.spi.ClassLoaderService) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Example 82 with HibernateException

use of org.hibernate.HibernateException in project head by mifos.

the class LegacyAccountDao method updateLedgerAccount.

public void updateLedgerAccount(COABO coaBo, String accountName, String glCode, String parentGlCode) throws PersistenceException {
    Session session = StaticHibernateUtil.getSessionTL();
    Transaction transaction = session.beginTransaction();
    try {
        Short newParentId = getAccountIdFromGlCode(parentGlCode);
        coaBo.setAccountName(accountName);
        GLCodeEntity glCodeEntity = coaBo.getAssociatedGlcode();
        createOrUpdate(coaBo);
        glCodeEntity.setGlcode(glCode);
        createOrUpdate(glCodeEntity);
        Query query = session.getNamedQuery(NamedQueryConstants.SET_COA_PARENT);
        query.setShort("parentId", newParentId);
        query.setShort("id", coaBo.getAccountId());
        query.executeUpdate();
        transaction.commit();
    } catch (HibernateException ex) {
        transaction.rollback();
        throw new PersistenceException(ex);
    }
}
Also used : Transaction(org.hibernate.Transaction) Query(org.hibernate.Query) HibernateException(org.hibernate.HibernateException) PersistenceException(org.mifos.framework.exceptions.PersistenceException) GLCodeEntity(org.mifos.accounts.financial.business.GLCodeEntity) Session(org.hibernate.Session)

Example 83 with HibernateException

use of org.hibernate.HibernateException in project head by mifos.

the class LegacyAccountDao method getCountForGlCode.

public int getCountForGlCode(Short glCodeId) throws PersistenceException {
    Session session = StaticHibernateUtil.getSessionTL();
    int count = -1;
    try {
        Query query = session.getNamedQuery(NamedQueryConstants.COUNT_GL_CODE_REFERENCES);
        query.setShort("glCodeId", glCodeId);
        count = (Integer) query.uniqueResult();
    } catch (HibernateException ex) {
        throw new PersistenceException(ex);
    }
    return count;
}
Also used : Query(org.hibernate.Query) HibernateException(org.hibernate.HibernateException) PersistenceException(org.mifos.framework.exceptions.PersistenceException) Session(org.hibernate.Session)

Example 84 with HibernateException

use of org.hibernate.HibernateException in project head by mifos.

the class LegacyRolesPermissionsDao method getUserRoles.

/**
     * This function returns the PersonRoles object which contains the person
     * information and the set of all the roles related to that user
     *
     * @param uid
     *            user id
     * @return PersonRoles
     * @throws HibernateProcessException
     */
public Set getUserRoles(short uid) throws SystemException, ApplicationException {
    Set roles = null;
    try {
        Session session = StaticHibernateUtil.getSessionTL();
        Query personRoles = session.getNamedQuery(NamedQueryConstants.GETPERSONROLES);
        personRoles.setShort("ID", uid);
        List<PersonRoles> lst = personRoles.list();
        if (null != lst && lst.size() > 0) {
            PersonRoles pr = lst.get(0);
            roles = pr.getRoles();
        }
    } catch (HibernateException he) {
        throw new SecurityException(SecurityConstants.GENERALERROR, he);
    }
    return roles;
}
Also used : Set(java.util.Set) Query(org.hibernate.Query) HibernateException(org.hibernate.HibernateException) PersonRoles(org.mifos.security.util.PersonRoles) SecurityException(org.mifos.framework.exceptions.SecurityException) Session(org.hibernate.Session)

Example 85 with HibernateException

use of org.hibernate.HibernateException in project head by mifos.

the class SystemInformationServiceFacadeWebTier method getServerInformation.

@Override
public String getServerInformation(ServletContext context, Locale locale) {
    try {
        DatabaseMetaData metaData = StaticHibernateUtil.getSessionTL().connection().getMetaData();
        final SystemInfo systemInfo = new SystemInfo(metaData, context, locale, true);
        return systemInfo.getApplicationServerInfo();
    } catch (HibernateException e) {
        throw new MifosRuntimeException(e);
    } catch (SQLException e) {
        throw new MifosRuntimeException(e);
    }
}
Also used : SystemInfo(org.mifos.application.admin.system.SystemInfo) HibernateException(org.hibernate.HibernateException) SQLException(java.sql.SQLException) DatabaseMetaData(java.sql.DatabaseMetaData) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Aggregations

HibernateException (org.hibernate.HibernateException)372 DAOException (org.jbei.ice.storage.DAOException)141 Session (org.hibernate.Session)72 Test (org.junit.Test)41 ArrayList (java.util.ArrayList)30 SQLException (java.sql.SQLException)27 IOException (java.io.IOException)15 TestForIssue (org.hibernate.testing.TestForIssue)15 Transaction (org.hibernate.Transaction)14 Group (org.jbei.ice.storage.model.Group)14 Type (org.hibernate.type.Type)12 PersistenceException (org.mifos.framework.exceptions.PersistenceException)12 Serializable (java.io.Serializable)11 EntityEntry (org.hibernate.engine.spi.EntityEntry)10 SessionFactoryImplementor (org.hibernate.engine.spi.SessionFactoryImplementor)10 HashMap (java.util.HashMap)9 Method (java.lang.reflect.Method)8 Dialect (org.hibernate.dialect.Dialect)8 CollectionPersister (org.hibernate.persister.collection.CollectionPersister)8 HibernateProxy (org.hibernate.proxy.HibernateProxy)8