List of usage examples for org.hibernate HibernateException HibernateException
public HibernateException(Throwable cause)
From source file:gov.nih.nci.iso21090.hibernate.tuple.IsoConstantTuplizerHelper.java
License:BSD License
/** * Finds field in class by going to super class. * @param klass klass in which the filedName is to be searched * @param fieldName name of the field to be retrieved * @return Field or exception/* w w w. ja va 2 s . com*/ */ @SuppressWarnings("PMD.EmptyCatchBlock") public Field findFieldInClass(Class klass, String fieldName) { Class tempKlass = klass; while (tempKlass != null && Object.class != tempKlass) { try { Field field = tempKlass.getDeclaredField(fieldName); if (field != null) { return field; } } catch (SecurityException e) { //No operation } catch (NoSuchFieldException e) { //No operation } tempKlass = tempKlass.getSuperclass(); } throw new HibernateException("No field found in class " + klass.getName() + " for " + fieldName); }
From source file:gov.nih.nci.iso21090.hibernate.tuple.IsoConstantTuplizerHelper.java
License:BSD License
private Object intantiatePropertyObject(String typeName) { try {//from w ww . ja v a 2 s.c o m //Field propertyField = findFieldInClass(parent.getClass(), propertyName); //Class propertyTypeClass = propertyField.getType(); Class propertyTypeClass = Class.forName(typeName); return propertyTypeClass.newInstance(); } catch (SecurityException e) { throw new HibernateException(e); } catch (IllegalAccessException e) { throw new HibernateException(e); } catch (InstantiationException e) { return null; // throw new HibernateException(e); } catch (ClassNotFoundException e) { throw new HibernateException(e); } }
From source file:gov.nih.nci.iso21090.hibernate.tuple.IsoConstantTuplizerHelper.java
License:BSD License
private Boolean setNullFlavor(Object parent) { Class klass = parent.getClass(); Boolean allNullFlavors = true; if (Any.class.isAssignableFrom(klass)) { if (((Any) parent).getNullFlavor() == null) { try { while (klass != null && klass != Object.class) { for (Field field : klass.getDeclaredFields()) { if (!Modifier.isStatic(field.getModifiers())) { field.setAccessible(true); Object value = field.get(parent); if (value == null) { setNullFlavor(parent, field.getName()); } else { if (Any.class.isAssignableFrom(value.getClass())) { if (!setNullFlavor(value)) allNullFlavors = false; if (((Any) value).getNullFlavor() != null) allNullFlavors = false; } else { allNullFlavors = false; }//from w w w . java 2 s . c o m } } } klass = klass.getSuperclass(); } } catch (SecurityException e) { throw new HibernateException(e); } catch (IllegalAccessException e) { throw new HibernateException(e); } catch (IllegalArgumentException e) { throw new HibernateException(e); } if (allNullFlavors) ((Any) parent).setNullFlavor(NullFlavor.NI); } } return allNullFlavors; }
From source file:gov.nih.nci.iso21090.hibernate.tuple.IsoCustomEntityTuplizer.java
License:BSD License
/** * Sets the values of the properties. In our case the nullFlavor. * /*from w ww.j av a 2 s . c o m*/ * @param entity Name of the entity. * @param values values to be set. */ @SuppressWarnings("PMD.CyclomaticComplexity") public void setPropertyValues(final Object entity, final Object[] values) { super.setPropertyValues(entity, values); try { String[] propertyNames = this.getEntityMetamodel().getPropertyNames(); String entityName = this.getEntityMetamodel().getName(); String identifierName = this.getEntityMetamodel().getIdentifierProperty().getName(); IsoConstantTuplizerHelper helper = new IsoConstantTuplizerHelper(); //Identifier can be null if the Tuplizer is for entity if (identifierName != null) { Object identifier = this.getIdentifier(entity); if (Any.class.isAssignableFrom(identifier.getClass())) { helper.setConstantValues(entity, identifier, entityName, identifierName, false); } } for (int i = 0; i < values.length; i++) { Class propertyTypeClass = helper.findFieldInClass(this.getMappedClass(), propertyNames[i]) .getType(); if (Any.class.isAssignableFrom(propertyTypeClass)) { helper.setConstantValues(entity, values[i], entityName, propertyNames[i], false); } } } catch (Exception e) { throw new HibernateException(e); } }
From source file:gr.interamerican.bo2.impl.open.hibernate.TestAbstractHibernatePersistenceUtility.java
License:Open Source License
/** * test newDataException().//from w w w.j ava2s.co m * */ @Test() @SuppressWarnings("nls") public void testNewDataException() { UserAHPU pu = new UserAHPU(); HibernateException hex = new HibernateException("msg"); User u = new User(); DataException dex = pu.newDataException(hex, u); Assert.assertNotNull(dex); Assert.assertEquals(hex, dex.getCause()); }
From source file:gr.interamerican.bo2.impl.open.hibernate.types.TwoWayConverterUserType.java
License:Open Source License
@SuppressWarnings({ "unchecked" }) public Object nullSafeGet(ResultSet rs, String[] names, Object owner) throws HibernateException, SQLException { Object column = TypeUtils.getTypeOfSqlType(sqlType).get(rs, names[0]); try {/*w w w. j a v a 2s . co m*/ return twoWayConverter.convertL((L) column); } catch (ConversionException e) { throw new HibernateException(e); } }
From source file:gr.interamerican.bo2.impl.open.hibernate.types.TwoWayConverterUserType.java
License:Open Source License
public void nullSafeSet(PreparedStatement st, Object value, int index) throws HibernateException, SQLException { R property = propertyClass.cast(value); try {/*from w w w. j av a 2s .c o m*/ L column = twoWayConverter.convertR(property); st.setObject(index, column, sqlType); } catch (ConversionException e) { throw new HibernateException(e); } }
From source file:grails.orm.RlikeExpression.java
License:Apache License
public String toSqlString(Criteria criteria, CriteriaQuery criteriaQuery) throws HibernateException { Dialect dialect = criteriaQuery.getFactory().getDialect(); String[] columns = criteriaQuery.getColumnsUsingProjection(criteria, propertyName); if (columns.length != 1) { throw new HibernateException("ilike may only be used with single-column properties"); }/*from ww w . j a va 2 s . c om*/ if (dialect instanceof MySQLDialect) { return columns[0] + " rlike ?"; } if (isOracleDialect(dialect)) { return " REGEXP_LIKE (" + columns[0] + ", ?)"; } return columns[0] + " like ?"; }
From source file:hibernate.dao.TbCareersDao.java
public void UpdateRow(TbCareers objTbCareer) throws HibernateException { try {/* ww w . j a va 2 s .co m*/ session = HibernateUtil.getSessionFactory().openSession(); transaction = session.beginTransaction(); session.save(objTbCareer); transaction.commit(); } catch (HibernateException ex) { transaction.rollback(); throw new HibernateException("Error in access to data... \b ->" + ex); } finally { session.close(); } }
From source file:hibernate.dao.TbCareersDao.java
public void DeleteRow(TbCareers objTbCareer) throws HibernateException { try {//from w ww . ja va 2 s.c o m session = HibernateUtil.getSessionFactory().openSession(); transaction = session.beginTransaction(); session.delete(objTbCareer); transaction.commit(); } catch (HibernateException ex) { transaction.rollback(); throw new HibernateException("Error in access to data... \b ->" + ex); } finally { session.close(); } }