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:com.fiveamsolutions.nci.commons.audit.DummyCompositeUserType.java

License:Open Source License

public void setPropertyValue(Object component, int property, Object value) throws HibernateException {
    DummyCompositeField var = (DummyCompositeField) component;
    switch (property) {
    case 0://from www  .  j  a v a 2 s  .  com
        var.setField1((String) value);
    case 1:
        var.setField2((Integer) value);
    case 2:
        var.setField3((Boolean) value);
    default:
        throw new HibernateException("Property " + property + " is invalid");
    }
}

From source file:com.flipkart.flux.type.BlobType.java

License:Apache License

/** Provides deep copy of an object using serialization and de-serialization*/
@Override//from w ww.java 2s.  c o m
public Object deepCopy(Object value) throws HibernateException {
    try {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        ObjectOutputStream oos = new ObjectOutputStream(baos);
        oos.writeObject(value);
        byte[] bytes = baos.toByteArray();
        ByteArrayInputStream baip = new ByteArrayInputStream(bytes);
        ObjectInputStream ois = new ObjectInputStream(baip);
        return ois.readObject();
    } catch (Exception e) {
        throw new HibernateException("Unable to deep copy. Exception: " + e.getMessage());
    }
}

From source file:com.floreantpos.model.dao.ShopFloorDAO.java

License:Open Source License

@Override
public void delete(ShopFloor shopFloor) throws HibernateException {
    Session session = null;/*ww  w .ja v a 2  s  . c  o  m*/
    Transaction tx = null;

    try {
        session = createNewSession();
        tx = session.beginTransaction();

        Set<ShopTable> tables = shopFloor.getTables();

        if (tables != null && !tables.isEmpty()) {
            shopFloor.getTables().removeAll(tables);
            saveOrUpdate(shopFloor);
        }

        super.delete(shopFloor, session);

        tx.commit();
    } catch (Exception e) {
        tx.rollback();
        LogFactory.getLog(ShopFloorDAO.class).error(e);

        throw new HibernateException(e);
    } finally {
        closeSession(session);
    }
}

From source file:com.floreantpos.model.dao._BaseRootDAO.java

License:Open Source License

protected void throwException(Throwable t) {
    if (t instanceof HibernateException)
        throw (HibernateException) t;
    else if (t instanceof RuntimeException)
        throw (RuntimeException) t;
    else//from w  ww. j  a  v a  2  s.  c o  m
        throw new HibernateException(t);
}

From source file:com.frameworkset.common.poolman.hibernate.LocalDataSourceConnectionProvider.java

License:Apache License

public void configure(Properties props) throws HibernateException {
    this.dataSource = LocalSessionFactoryBean.getConfigTimeDataSource();
    // absolutely needs thread-bound DataSource to initialize
    if (this.dataSource == null) {
        throw new HibernateException("No local DataSource found for configuration - "
                + "'dataSource' property must be set on LocalSessionFactoryBean");
    }/*www .  j  a  v a  2s . c o m*/
    this.dataSourceToUse = getDataSourceToUse(this.dataSource);
}

From source file:com.frameworkset.common.poolman.hibernate.SimpleDatasourceConnectionProvider.java

License:Apache License

public void configure(Properties props) throws HibernateException {
    this.dataSource = SQLManager.getTXDatasourceByDBName(dbname);
    // absolutely needs thread-bound DataSource to initialize
    if (this.dataSource == null) {
        throw new HibernateException("No local DataSource found for configuration - "
                + "'dataSource' property must be set on LocalSessionFactoryBean");
    }/*w  w  w.j a  v a2  s .c om*/
    this.dataSourceToUse = getDataSourceToUse(this.dataSource);
}

From source file:com.gisgraphy.hibernate.type.TsVectorStringType.java

License:Open Source License

public void nullSafeSet(PreparedStatement st, Object value, int index) throws HibernateException, SQLException {
    if (value != null) {
        if (!(value instanceof String)) {
            throw new HibernateException(
                    "object must be a string to be converted but was " + value.getClass().getName());
        }//from w  w  w  .ja v  a  2 s .  c om
        //the code bellow doens't work because there is no jdbc extension for tsvector object
        //st.setObject(index,"(select to_tsvector('"+((String) value)+"'))",25);
        st.setNull(index, sqlTypes()[0]);
    } else {
        st.setNull(index, sqlTypes()[0]);
    }

}

From source file:com.github.pires.example.hibernate.user.types.JSONBUserType.java

License:Apache License

@Override
public Object nullSafeGet(ResultSet resultSet, String[] names, SessionImplementor session, Object owner)
        throws HibernateException, SQLException {
    try {/*from   ww  w  . ja v a2 s  . c o m*/
        final String json = resultSet.getString(names[0]);
        return json == null ? null : MAPPER.readValue(json, returnedClass);
    } catch (IOException ex) {
        throw new HibernateException(ex);
    }
}

From source file:com.github.pires.example.hibernate.user.types.JSONBUserType.java

License:Apache License

@Override
public void nullSafeSet(PreparedStatement st, Object value, int index, SessionImplementor session)
        throws HibernateException, SQLException {
    try {//from   ww w.j  a v  a 2 s  . c om
        final String json = value == null ? null : MAPPER.writeValueAsString(value);
        // otherwise PostgreSQL won't recognize the type
        PGobject pgo = new PGobject();
        pgo.setType(getType());
        pgo.setValue(json);
        st.setObject(index, pgo);
    } catch (JsonProcessingException ex) {
        throw new HibernateException(ex);
    }
}

From source file:com.globalsight.ling.tm3.core.BaseTm.java

License:Apache License

public void addAttribute(TM3Attribute attr) throws HibernateException {
    try {/*from w  ww . ja  v a2s. c  o  m*/
        HibernateUtil.save(attr);
    } catch (Exception e) {
        throw new HibernateException(e);
    }
    attributes.add(attr);
}