use of org.hibernate.HibernateException in project hibernate-orm by hibernate.
the class TypeFactorySerializationTest method testUnregisterSerializeRegisterDiffSessionFactory.
@Test
public void testUnregisterSerializeRegisterDiffSessionFactory() throws Exception {
Configuration cfg = new Configuration().setProperty(AvailableSettings.SESSION_FACTORY_NAME, NAME).setProperty(AvailableSettings.SESSION_FACTORY_NAME_IS_JNDI, // default is true
"false");
SessionFactoryImplementor factory = (SessionFactoryImplementor) cfg.buildSessionFactory();
assertSame(factory, SessionFactoryRegistry.INSTANCE.getNamedSessionFactory(NAME));
// Remove the session factory from the registry
SessionFactoryRegistry.INSTANCE.removeSessionFactory(factory.getUuid(), NAME, false, null);
assertNull(SessionFactoryRegistry.INSTANCE.findSessionFactory(factory.getUuid(), NAME));
TypeFactory typeFactory = factory.getTypeResolver().getTypeFactory();
byte[] typeFactoryBytes = SerializationHelper.serialize(typeFactory);
typeFactory = (TypeFactory) SerializationHelper.deserialize(typeFactoryBytes);
try {
typeFactory.resolveSessionFactory();
fail("should have failed with HibernateException because session factory is not registered.");
} catch (HibernateException ex) {
// expected because the session factory is not registered.
}
// Now create a new session factory with the same name; it will have a different UUID.
SessionFactoryImplementor factoryWithSameName = (SessionFactoryImplementor) cfg.buildSessionFactory();
assertSame(factoryWithSameName, SessionFactoryRegistry.INSTANCE.getNamedSessionFactory(NAME));
assertFalse(factory.getUuid().equals(factoryWithSameName.getUuid()));
// Session factory resolved from typeFactory should be the new session factory
// (because it is resolved from SessionFactoryRegistry.INSTANCE)
assertSame(factoryWithSameName, typeFactory.resolveSessionFactory());
factory.close();
factoryWithSameName.close();
}
use of org.hibernate.HibernateException in project hibernate-orm by hibernate.
the class TypeFactorySerializationTest method testUnregisterSerializeRegisterDiffSessionFactoryNoName.
@Test
public void testUnregisterSerializeRegisterDiffSessionFactoryNoName() throws Exception {
Configuration cfg = new Configuration();
SessionFactoryImplementor factory = (SessionFactoryImplementor) cfg.buildSessionFactory();
assertSame(factory, SessionFactoryRegistry.INSTANCE.getSessionFactory(factory.getUuid()));
// Remove the session factory from the registry
SessionFactoryRegistry.INSTANCE.removeSessionFactory(factory.getUuid(), null, false, null);
assertNull(SessionFactoryRegistry.INSTANCE.getSessionFactory(factory.getUuid()));
TypeFactory typeFactory = factory.getTypeResolver().getTypeFactory();
byte[] typeFactoryBytes = SerializationHelper.serialize(typeFactory);
typeFactory = (TypeFactory) SerializationHelper.deserialize(typeFactoryBytes);
try {
typeFactory.resolveSessionFactory();
fail("should have failed with HibernateException because session factory is not registered.");
} catch (HibernateException ex) {
// expected because the session factory is not registered.
}
// Now create a new session factory with the same name; it will have a different UUID.
SessionFactoryImplementor factoryWithDiffUuid = (SessionFactoryImplementor) cfg.buildSessionFactory();
assertSame(factoryWithDiffUuid, SessionFactoryRegistry.INSTANCE.getSessionFactory(factoryWithDiffUuid.getUuid()));
assertFalse(factory.getUuid().equals(factoryWithDiffUuid.getUuid()));
// It should not be possible to resolve the session factory with no name configured.
try {
typeFactory.resolveSessionFactory();
fail("should have failed with HibernateException because session factories were not registered with the same non-null name.");
} catch (HibernateException ex) {
// expected
}
factory.close();
factoryWithDiffUuid.close();
}
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);
}
}
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;
}
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;
}
Aggregations