List of usage examples for org.hibernate HibernateException HibernateException
public HibernateException(String message, Throwable cause)
From source file:com.ge.current.innovation.storage.jpa.boot.FeatureCollectionGeoJsonUserType.java
/** * Retrieve an instance of the mapped class from a JDBC resultset. * Implementors should handle possibility of null values. * * @param rs a JDBC result set//from w w w . j a va 2 s.c o m * @param names the column names * @param session * @param owner the containing entity * @return * @throws HibernateException * @throws SQLException */ @Override public Object nullSafeGet(ResultSet rs, String[] names, SessionImplementor session, Object owner) throws HibernateException, SQLException { try { return objectMapper.readValue(rs.getString(names[0]), FeatureCollection.class); } catch (IOException ex) { throw new HibernateException("Could not deserialize json " + rs.getString(names[0]), ex); } }
From source file:com.ge.current.innovation.storage.jpa.boot.FeatureGeoJsonUserType.java
/** * Retrieve an instance of the mapped class from a JDBC resultset. * Implementors should handle possibility of null values. * * @param rs a JDBC result set//from ww w . jav a 2 s.c o m * @param names the column names * @param session * @param owner the containing entity * @return * @throws HibernateException * @throws SQLException */ @Override public Object nullSafeGet(ResultSet rs, String[] names, SessionImplementor session, Object owner) throws HibernateException, SQLException { try { return objectMapper.readValue(rs.getString(names[0]), Feature.class); } catch (IOException ex) { throw new HibernateException("Could not deserialize json " + rs.getString(names[0]), ex); } }
From source file:com.googlecode.hibernate.audit.listener.AuditListener.java
License:Open Source License
private void processAuditConfigurationObserver(SessionFactoryServiceRegistry serviceRegistry) { String observerClazzProperty = serviceRegistry.getService(ConfigurationService.class) .getSetting(HibernateAudit.AUDIT_CONFIGURATION_OBSERVER_PROPERTY, StandardConverters.STRING, null); if (observerClazzProperty != null) { ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader(); Class observerClazz = null; try {/*from w ww .ja va2s . c o m*/ observerClazz = contextClassLoader.loadClass(observerClazzProperty); } catch (ClassNotFoundException ignored) { } try { if (observerClazz == null) { observerClazz = AuditListener.class.forName(observerClazzProperty); } } catch (ClassNotFoundException e) { throw new HibernateException( "Unable to find audit configuration observer class:" + observerClazzProperty, e); } try { AuditConfigurationObserver observer = (AuditConfigurationObserver) observerClazz.newInstance(); observer.auditConfigurationCreated(auditConfiguration); } catch (InstantiationException e) { throw new HibernateException( "Unable to instantiate audit configuration observer from class:" + observerClazzProperty, e); } catch (IllegalAccessException e) { throw new HibernateException( "Unable to instantiate audit configuration observer from class:" + observerClazzProperty, e); } catch (ClassCastException e) { throw new HibernateException("Audit configuration observer class:" + observerClazzProperty + " should implement " + AuditConfigurationObserver.class.getName(), e); } } }
From source file:com.jaspersoft.hibernate.ByteWrappingBlobType.java
License:Open Source License
/** * on calling get(), let's just call getObject() and see what happens, then turn it * into a blob if it isn't one.//from w w w.ja v a2s . co m */ public Object get(ResultSet rs, String name) throws HibernateException, SQLException { Object value = rs.getObject(name); if (rs.wasNull()) { return null; } if (value instanceof Blob) { log.debug("getting blob for " + name); return DataContainerStreamUtil.createComparableBlob((Blob) value); } else if (value instanceof byte[]) { log.debug("getting byte[" + ((byte[]) value).length + "] for " + name); return DataContainerStreamUtil.createComparableBlob((byte[]) value); } else if (value instanceof InputStream) { try { log.debug("getting input stream for " + name); return DataContainerStreamUtil.createComparableBlob((InputStream) value); } catch (Exception e) { throw new HibernateException("exception creating blob from input stream", e); } } else { throw new HibernateException( "I don't know how to map the type " + value.getClass().getName() + " to a blob"); } }
From source file:com.mangocity.util.dao.GenericDAOHibernateImpl.java
License:Open Source License
@Deprecated public void execProcedure(final String sql, final Object[] paramValues) { try {// www. j a v a 2s . co m getHibernateTemplate().execute(new HibernateCallback() { public Object doInHibernate(Session session) throws HibernateException { try { Connection conn = session.connection(); CallableStatement stmt = conn.prepareCall(sql); if (paramValues != null && paramValues.length > 0) { for (int idx = 1; idx <= paramValues.length; idx++) { stmt.setObject(idx, paramValues[idx - 1]); //TODO } } stmt.execute(); } catch (SQLException sqlException) { throw new HibernateException(sqlException.getMessage(), sqlException); } return null; } }); } catch (DataAccessException dae) { throw new DAException(DataAccessError.DATA_ACCESS_FAILED, dae); } }
From source file:com.mangocity.util.dao.GenericDAOHibernateImpl.java
License:Open Source License
@SuppressWarnings("unchecked") @Deprecated/*w ww .j av a 2 s . co m*/ public Map<Integer, ?> execProcedure(final String sql, final Map<Integer, ?> inParamsIdxAndValue, final Map<Integer, Integer> outParamsIdxAndType) { Map<Integer, ?> result = null; try { result = (Map<Integer, ?>) getHibernateTemplate().execute(new HibernateCallback() { public Object doInHibernate(Session session) throws HibernateException { CallableStatement cstmt = null; Map resultMap = new HashMap(outParamsIdxAndType.size()); try { Connection conn = session.connection(); cstmt = conn.prepareCall(sql); if (inParamsIdxAndValue != null && !inParamsIdxAndValue.isEmpty()) { for (Map.Entry<Integer, ?> inParamsEntry : inParamsIdxAndValue.entrySet()) { cstmt.setObject(inParamsEntry.getKey().intValue(), inParamsEntry.getValue());//TODO } } for (Map.Entry<Integer, Integer> outParamsEntry : outParamsIdxAndType.entrySet()) { cstmt.registerOutParameter(outParamsEntry.getKey().intValue(), outParamsEntry.getValue().intValue()); } cstmt.execute(); //Map? for (Map.Entry<Integer, Integer> outParamsEntry : outParamsIdxAndType.entrySet()) { resultMap.put(outParamsEntry.getKey(), cstmt.getObject(outParamsEntry.getKey().intValue())); } } catch (SQLException sqlException) { throw new HibernateException(sqlException.getMessage(), sqlException); } finally { try { cstmt.close(); } catch (SQLException sqlException) { throw new HibernateException(sqlException.getMessage(), sqlException); } } return resultMap; } }); } catch (DataAccessException dae) { throw new DAException(DataAccessError.DATA_ACCESS_FAILED, dae); } return result; }
From source file:com.mg.framework.support.orm.EnumUserType.java
License:Open Source License
public void setParameterValues(Properties parameters) { String enumClassName = parameters.getProperty("enumClass"); try {/*from w w w.j ava 2 s. c om*/ enumClass = Thread.currentThread().getContextClassLoader().loadClass(enumClassName) .asSubclass(Enum.class); } catch (ClassNotFoundException cnfe) { throw new HibernateException("Enum class not found", cnfe); } }
From source file:com.mg.jet.birt.report.data.oda.ejbql.HibernateUtil.java
License:Open Source License
private static synchronized void initSessionFactory(String hibfile, String mapdir, String jndiName) throws HibernateException { //ClassLoader cl1; if (sessionFactory == null) { if (jndiName == null || jndiName.trim().length() == 0) jndiName = CommonConstant.DEFAULT_JNDI_URL; Context initCtx = null;//from w w w . ja v a2 s . co m try { initCtx = new InitialContext(); sessionFactory = (SessionFactory) initCtx.lookup(jndiName); return; } catch (Exception e) { logger.log(Level.INFO, "Unable to get JNDI data source connection", e); } finally { if (initCtx != null) try { initCtx.close(); } catch (NamingException e) { //ignore } } Thread thread = Thread.currentThread(); try { //Class.forName("org.hibernate.Configuration"); //Configuration ffff = new Configuration(); //Class.forName("org.apache.commons.logging.LogFactory"); oldloader = thread.getContextClassLoader(); //Class thwy = oldloader.loadClass("org.hibernate.cfg.Configuration"); //Class thwy2 = oldloader.loadClass("org.apache.commons.logging.LogFactory"); //refreshURLs(); //ClassLoader changeLoader = new URLClassLoader( (URL [])URLList.toArray(new URL[0]),HibernateUtil.class.getClassLoader()); ClassLoader testLoader = new URLClassLoader((URL[]) URLList.toArray(new URL[0]), pluginLoader); //changeLoader = new URLClassLoader( (URL [])URLList.toArray(new URL[0])); thread.setContextClassLoader(testLoader); //Class thwy2 = changeLoader.loadClass("org.hibernate.cfg.Configuration"); //Class.forName("org.apache.commons.logging.LogFactory", true, changeLoader); //Class cls = Class.forName("org.hibernate.cfg.Configuration", true, changeLoader); //Configuration cfg=null; //cfg = new Configuration(); //Object oo = cls.newInstance(); //Configuration cfg = (Configuration)oo; Configuration cfg = new Configuration(); buildConfig(hibfile, mapdir, cfg); Class<? extends Driver> driverClass = testLoader .loadClass(cfg.getProperty("connection.driver_class")).asSubclass(Driver.class); Driver driver = driverClass.newInstance(); WrappedDriver wd = new WrappedDriver(driver, cfg.getProperty("connection.driver_class")); boolean foundDriver = false; Enumeration<Driver> drivers = DriverManager.getDrivers(); while (drivers.hasMoreElements()) { Driver nextDriver = (Driver) drivers.nextElement(); if (nextDriver.getClass() == wd.getClass()) { if (nextDriver.toString().equals(wd.toString())) { foundDriver = true; break; } } } if (!foundDriver) { DriverManager.registerDriver(wd); } sessionFactory = cfg.buildSessionFactory(); //configuration = cfg; HibernateMapDirectory = mapdir; HibernateConfigFile = hibfile; } catch (Throwable e) { e.printStackTrace(); throw new HibernateException("No Session Factory Created " + e.getLocalizedMessage(), e); } finally { thread.setContextClassLoader(oldloader); } } }
From source file:com.namphibian.pgdilato.PostgresqlUserDefinedArrayType.java
@Override public void setParameterValues(Properties params) { String classTypeName = params.getProperty(CLASS_TYPE); try {//from w w w.j a va 2 s.c om this.classType = ReflectHelper.classForName(classTypeName, this.getClass()); } catch (ClassNotFoundException cnfe) { throw new HibernateException("classType not found", cnfe); } String converterTypeName = params.getProperty(CONVERTER_TYPE); try { try { converter = (PgStructToClassInterface) ReflectHelper .classForName(converterTypeName, this.getClass()).newInstance(); //this.classType = ReflectHelper.classForName(classTypeName, this.getClass()); } catch (InstantiationException ex) { Logger.getLogger(PostgresqlUserDefinedArrayType.class.getName()).log(Level.SEVERE, null, ex); throw new HibernateException(ex.getMessage()); } catch (IllegalAccessException ex) { Logger.getLogger(PostgresqlUserDefinedArrayType.class.getName()).log(Level.SEVERE, null, ex); throw new HibernateException(ex.getMessage()); } } catch (ClassNotFoundException cnfe) { throw new HibernateException("classType not found", cnfe); } this.sqlType = Types.OTHER; this.pgsqlType = params.getProperty(PGSQL_TYPE); }
From source file:com.namphibian.pgdilato.PostgresqlUserDefinedType.java
@Override public void setParameterValues(Properties params) { String classTypeName = params.getProperty(CLASS_TYPE); try {/*from w w w.j av a 2 s .c o m*/ this.classType = ReflectHelper.classForName(classTypeName, this.getClass()); } catch (ClassNotFoundException cnfe) { throw new HibernateException("classType not found", cnfe); } this.sqlType = Types.JAVA_OBJECT; this.pgsqlType = params.getProperty(PGSQL_TYPE); }