Example usage for org.hibernate HibernateException HibernateException

List of usage examples for org.hibernate HibernateException HibernateException

Introduction

In this page you can find the example usage for org.hibernate HibernateException HibernateException.

Prototype

public HibernateException(Throwable cause) 

Source Link

Document

Constructs a HibernateException using the given message and underlying cause.

Usage

From source file:br.eb.ime.pfc.hibernate.HibernateUtil.java

License:Open Source License

public static Session getCurrentSession() throws HibernateException {
    if (sessionFactory != null) {
        //Throws HibernateException if there is no Session open.
        return sessionFactory.getCurrentSession();
    } else {/*w ww  .jav a 2 s  . c o m*/
        throw new HibernateException("No session open.");
    }
}

From source file:ca.myewb.frame.HibernateUtil.java

License:Open Source License

public static Session currentSession() throws HibernateException {
    if (!isBuilding) {
        try {/*from w  ww  .  j  a  v  a2  s .c  o m*/
            Session s = sessionHolder.get();

            // Open a new Session, if this Thread has none yet
            if ((s == null) || (s.isOpen() == false)) {
                s = sessionFactory.openSession();
                sessionHolder.set(s);
            }

            return s;
        } catch (Exception ex) {
            log.fatal("Problem getting session");
            throw new HibernateException(ex);
        }
    } else {
        return null;
    }
}

From source file:ca.myewb.frame.HibernateUtil.java

License:Open Source License

public static void closeSession() throws HibernateException {
    try {//  w w  w.ja va 2s  . co m
        Session s = sessionHolder.get();
        sessionHolder.set(null);

        // Close the session if one exists
        if (s != null) {
            s.clear();
            s.close();
        }
    } catch (Exception ex) {
        log.fatal("Problem closing session");
        throw new HibernateException(ex);
    }
}

From source file:cn.guoyukun.spring.jpa.repository.hibernate.type.CollectionToStringUserType.java

License:Apache License

@Override
public void setParameterValues(Properties parameters) {
    String separator = (String) parameters.get("separator");
    if (!StringUtils.isEmpty(separator)) {
        this.separator = separator;
    } else {//w  ww  . ja  va 2  s. c  o m
        this.separator = ",";
    }

    String collectionType = (String) parameters.get("collectionType");
    if (!StringUtils.isEmpty(collectionType)) {
        try {
            this.collectionType = Class.forName(collectionType);
        } catch (ClassNotFoundException e) {
            throw new HibernateException(e);
        }
    } else {
        this.collectionType = java.util.ArrayList.class;
    }

    String elementType = (String) parameters.get("elementType");
    if (!StringUtils.isEmpty(elementType)) {
        try {
            this.elementType = Class.forName(elementType);
        } catch (ClassNotFoundException e) {
            throw new HibernateException(e);
        }
    } else {
        this.elementType = Long.TYPE;
    }
}

From source file:cn.guoyukun.spring.jpa.repository.hibernate.type.CollectionToStringUserType.java

License:Apache License

private Collection newCollection() {
    try {/*from www . j a v  a2  s. c  om*/
        return (Collection) collectionType.newInstance();
    } catch (Exception e) {
        throw new HibernateException(e);
    }
}

From source file:cn.guoyukun.spring.jpa.repository.hibernate.type.HashMapToStringUserType.java

License:Apache License

@Override
public void setParameterValues(Properties parameters) {
    String keyType = (String) parameters.get("keyType");
    if (!StringUtils.isEmpty(keyType)) {
        try {/*w  w  w.j a va 2  s . c  o  m*/
            this.keyType = Class.forName(keyType);
        } catch (ClassNotFoundException e) {
            throw new HibernateException(e);
        }
    } else {
        this.keyType = String.class;
    }

}

From source file:cn.guoyukun.spring.jpa.repository.hibernate.type.HashMapToStringUserType.java

License:Apache License

/**
 * JDBC ResultSet??,??//from ww  w. java  2s  . c  om
 * (?null?)
 * names????
 *
 * @param names
 * @param owner
 * @return
 * @throws org.hibernate.HibernateException
 * @throws java.sql.SQLException
 */
@Override
public Object nullSafeGet(ResultSet rs, String[] names, SessionImplementor session, Object owner)
        throws HibernateException, SQLException {
    String valueStr = rs.getString(names[0]);
    if (StringUtils.isEmpty(valueStr)) {
        return newMap();
    }

    Map map = JSONObject.parseObject(valueStr);
    Map result = newMap();
    try {
        for (Object key : map.keySet()) {
            Object value = map.get(key);
            result.put(keyType.getConstructor(String.class).newInstance(key), value);
        }
    } catch (Exception e) {
        e.printStackTrace();
        throw new HibernateException(e);
    }
    return result;
}

From source file:cn.guoyukun.spring.jpa.repository.hibernate.type.HashMapToStringUserType.java

License:Apache License

private Map<?, ?> newMap() {
    try {/*from   w  ww  .j  av a2  s . c  om*/
        return HashMap.class.newInstance();
    } catch (Exception e) {
        throw new HibernateException(e);
    }
}

From source file:cn.guoyukun.spring.jpa.repository.hibernate.type.LinkedHashMapToStringUserType.java

License:Apache License

private Map<?, ?> newMap() {
    try {/*ww  w .  j a v a 2s .com*/
        return LinkedHashMap.class.newInstance();
    } catch (Exception e) {
        throw new HibernateException(e);
    }
}

From source file:cn.guoyukun.spring.jpa.repository.hibernate.type.ObjectSerializeUserType.java

License:Apache License

/**
 * JDBC ResultSet??,??//  w  w w . java2 s.c o  m
 * (?null?)
 * names????
 *
 * @param names
 * @param owner
 * @return
 * @throws HibernateException
 * @throws SQLException
 */
@Override
public Object nullSafeGet(ResultSet rs, String[] names, SessionImplementor session, Object owner)
        throws HibernateException, SQLException {
    ObjectInputStream ois = null;
    try {
        String hexStr = rs.getString(names[0]);
        ois = new ObjectInputStream(new ByteArrayInputStream(Hex.decodeHex(hexStr.toCharArray())));
        return ois.readObject();
    } catch (Exception e) {
        throw new HibernateException(e);
    } finally {
        try {
            ois.close();
        } catch (IOException e) {
        }
    }
}