List of usage examples for org.hibernate HibernateException HibernateException
public HibernateException(String message, Throwable cause)
From source file:edu.wustl.common.hibernate.HibernateUtil.java
License:BSD License
public static Session newSession() { Session session = m_sessionFactory.openSession(); session.setFlushMode(FlushMode.COMMIT); try {/*w ww.j a va 2 s . c o m*/ session.connection().setAutoCommit(false); } catch (SQLException ex) { throw new HibernateException(ex.getMessage(), ex); } return session; }
From source file:gov.nih.nci.caintegrator.common.GenericEnumUserType.java
License:BSD License
/** * {@inheritDoc}//from w w w . ja v a 2s . c om */ @Override public void setParameterValues(Properties parameters) { String enumClassName = parameters.getProperty("enumClass"); Class<?> identifierType; try { enumClass = Class.forName(enumClassName).asSubclass(Enum.class); } catch (ClassNotFoundException cfne) { throw new HibernateException("Enum class not found: " + enumClassName, cfne); } String identifierMethodName = parameters.getProperty("identifierMethod", DEFAULT_IDENTIFIER_METHOD_NAME); try { identifierMethod = enumClass.getMethod(identifierMethodName, new Class[0]); identifierType = identifierMethod.getReturnType(); } catch (Exception e) { throw new HibernateException("Failed to obtain identifier method", e); } type = (NullableType) TypeFactory.basic(identifierType.getName()); if (type == null) { throw new HibernateException("Unsupported identifier type " + identifierType.getName()); } mySqlTypes = new int[] { type.sqlType() }; String valueOfMethodName = parameters.getProperty("valueOfMethod", DEFAULT_VALUE_OF_METHOD_NAME); try { valueOfMethod = enumClass.getMethod(valueOfMethodName, new Class[] { identifierType }); } catch (Exception e) { throw new HibernateException("Failed to obtain valueOf method", e); } }
From source file:gov.nih.nci.caintegrator.common.GenericEnumUserType.java
License:BSD License
/** * {@inheritDoc}/*from www.j av a 2s. c om*/ */ @Override public Object nullSafeGet(ResultSet rs, String[] names, Object owner) throws SQLException { Object identifier = type.get(rs, names[0]); if (rs.wasNull()) { return null; } try { return valueOfMethod.invoke(enumClass, new Object[] { identifier }); } catch (Exception e) { throw new HibernateException("Exception while invoking valueOf method '" + valueOfMethod.getName() + "' of " + "enumeration class '" + enumClass + "'", e); } }
From source file:gov.nih.nci.caintegrator.common.GenericEnumUserType.java
License:BSD License
/** * {@inheritDoc}/* w w w . j ava 2 s .c o m*/ */ @Override public void nullSafeSet(PreparedStatement st, Object value, int index) throws SQLException { try { if (value == null) { st.setNull(index, type.sqlType()); } else { Object identifier = identifierMethod.invoke(value, new Object[0]); type.set(st, identifier, index); } } catch (Exception e) { throw new HibernateException("Exception while invoking identifierMethod '" + identifierMethod.getName() + "' of " + "enumeration class '" + enumClass + "'", e); } }
From source file:gov.nih.nci.iso21090.hibernate.tuple.IsoConstantTuplizerHelper.java
License:BSD License
private Object convertValue(Object value, Class targetType) { if (value == null) { return null; }// w w w . jav a2s. c o m if (targetType.isAssignableFrom(value.getClass())) { return value; } try { if (value.getClass() == String.class) { if (Boolean.class == targetType) { if ("1".equals(value)) { return Boolean.TRUE; } else if ("0".equals(value)) { return Boolean.FALSE; } else { return Boolean.valueOf((String) value); } } else if (Integer.class == targetType) { return Integer.valueOf((String) value); } else if (BigDecimal.class == targetType) { return BigDecimal.valueOf(Double.valueOf((String) value)); } else if (URI.class == targetType) { return new URI((String) value); } } } catch (Exception e) { throw new HibernateException( "Error in converting String tyoe to " + targetType.getName() + " for " + value, e); } throw new HibernateException("Can not convert Non-String type to target type of " + targetType.getName()); }
From source file:gr.interamerican.bo2.impl.open.hibernate.types.OneBasedEnumUserType.java
License:Open Source License
@SuppressWarnings({ "unchecked", "nls" }) public void setParameterValues(Properties parameters) { String enumClassName = parameters.getProperty("enumClassName"); try {/*from w w w. ja v a 2 s . c om*/ enumClass = (Class<Enum>) Class.forName(enumClassName); } catch (ClassNotFoundException cnfe) { throw new HibernateException("Enum class not found", cnfe); } }
From source file:hibernate.dao.TbCareersDao.java
public long InsertRow(TbCareers objTbCareer) throws HibernateException { long rowId = 0; try {//w ww . j a v a2 s .c o m session = HibernateUtil.getSessionFactory().openSession(); transaction = session.beginTransaction(); rowId = (Long) session.save(objTbCareer); transaction.commit(); } catch (HibernateException ex) { transaction.rollback(); throw new HibernateException("Error in access to data... \b ->", ex); } finally { session.close(); } return rowId; }
From source file:it.scoppelletti.programmerpower.data.types.SimpleDateTypeDescriptor.java
License:Apache License
/** * Converte una stringa in un valore.//w ww . j av a2 s. com * * @param s Stringa. * @return Valore. */ @Override public SimpleDate fromString(String s) { Calendar cal; Date value; if (Strings.isNullOrEmpty(s)) { return SimpleDate.NIL; } try { value = myFormat.parse(s); } catch (ParseException ex) { throw new HibernateException(String.format("Failed to parse string \"%1$s\".", s), ex); } cal = Calendar.getInstance(); cal.setTime(value); return SimpleDate.toSimpleDate(cal); }
From source file:it.scoppelletti.programmerpower.data.types.SimpleTimestampTypeDescriptor.java
License:Apache License
/** * Converte una stringa in un valore.//from ww w .ja v a 2 s . com * * @param s Stringa. * @return Valore. */ @Override public SimpleTimestamp fromString(String s) { Calendar cal; Date value; if (Strings.isNullOrEmpty(s)) { return SimpleTimestamp.NIL; } try { value = myFormat.parse(s); } catch (ParseException ex) { throw new HibernateException(String.format("Failed to parse string \"%1$s\".", s), ex); } cal = Calendar.getInstance(); cal.setTime(value); return SimpleTimestamp.toSimpleTimestamp(cal); }
From source file:it.scoppelletti.programmerpower.data.types.SimpleTimeTypeDescriptor.java
License:Apache License
/** * Converte una stringa in un valore./*from www. j a v a 2 s . c o m*/ * * @param s Stringa. * @return Valore. */ @Override public SimpleTime fromString(String s) { Calendar cal; Date value; if (Strings.isNullOrEmpty(s)) { return null; } try { value = myFormat.parse(s); } catch (ParseException ex) { throw new HibernateException(String.format("Failed to parse string \"%1$s\".", s), ex); } cal = Calendar.getInstance(); cal.setTime(value); return new SimpleTime(cal); }