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:dao.RodadaDao.java

public List<Rodada> listarRodadasAbertasPorCompeticao(Competicao competicao) {
    try {/*from w w w  .j a  v  a2 s. c  o  m*/
        if (competicao == null) {
            return null;
        }

        Session sessao = Hibernate4Util.getSessionFactory();
        Transaction transacao = sessao.beginTransaction();
        Query consulta = sessao.createQuery("SELECT ro " + " FROM Rodada ro" + " JOIN ro.competicao c"
                + " WHERE c = ?" + " AND (fechada IS NULL) OR (fechada = false)");
        consulta.setEntity(0, competicao);
        List<Rodada> resultado = consulta.list();
        transacao.commit();
        return resultado;
    } catch (HibernateException e) {
        System.out.println("No foi possvel selecionar as rodadas. Erro: " + e.getMessage());
        throw new HibernateException(e);
    }
}

From source file:dao.TimeCompeticaoDao.java

public List<TimeCompeticao> listar() {
    try {/*from ww  w .ja  v  a  2s .  co  m*/
        Session sessao = Hibernate4Util.getSessionFactory();
        Transaction transacao = sessao.beginTransaction();
        Criteria cr = sessao.createCriteria(TimeCompeticao.class);
        List<TimeCompeticao> resultado = cr.list();
        transacao.commit();
        return resultado;
    } catch (HibernateException e) {
        System.out.println(
                "No foi possvel selecionar vinculos de times por competio. Erro: " + e.getMessage());
        throw new HibernateException(e);
    }
}

From source file:dao.TimeCompeticaoDao.java

public List<TimeCompeticao> listarPorCompeticao(Competicao competicao) {
    try {/*from   ww  w  .  j  a va  2s .co m*/
        Session sessao = Hibernate4Util.getSessionFactory();
        Transaction transacao = sessao.beginTransaction();
        Query consulta = sessao.createQuery("SELECT tc " + " FROM TimeCompeticao tc"
                + " INNER JOIN tc.competicao AS cm" + " WHERE (cm = ?)");
        consulta.setEntity(0, competicao);
        List<TimeCompeticao> resultado = consulta.list();
        transacao.commit();
        return resultado;
    } catch (HibernateException e) {
        System.out.println(
                "No foi possvel selecionar o vinculo de time por competio. Erro: " + e.getMessage());
        throw new HibernateException(e);
    }
}

From source file:dao.TimeDao.java

/**
 * Obtm lista com todos os times do banco
 *
 * @return Lista com todos os times do banco
 */// w w w. j  a v a2  s.  co m
public List<Time> listar() {
    try {
        Session sessao = Hibernate4Util.getSessionFactory();
        Transaction transacao = sessao.beginTransaction();
        Criteria cr = sessao.createCriteria(Time.class);
        List<Time> resultado = cr.list();
        transacao.commit();
        return resultado;
    } catch (HibernateException e) {
        System.out.println("No foi possvel selecionar times. Erro: " + e.getMessage());
        throw new HibernateException(e);
    }
}

From source file:dao.TimeDao.java

/**
 * Obtm lista com todos os times do banco
 *
 * @param nome Nome a ser filtrado//from w w w . j  a  va  2s  .  c  o  m
 * @return Lista com todos os times do banco
 */
public List<Time> listarPorNome(String nome) {
    try {
        Session sessao = Hibernate4Util.getSessionFactory();
        Transaction transacao = sessao.beginTransaction();
        Query consulta = sessao.createQuery("from Time where nome like :nome order by nome, dataFundacao");
        consulta.setString("nome", "%" + nome + "%");

        List<Time> resultado = consulta.list();
        transacao.commit();
        return resultado;
    } catch (HibernateException e) {
        System.out.println("No foi possvel selecionar times. Erro: " + e.getMessage());
        throw new HibernateException(e);
    }
}

From source file:dao.TimeDao.java

/**
 * Obtm lista com todos os times do banco
 *
 * @param dataIni Data inicial a ser filtrada
 * @param dataFin Data final a ser filtrada
 * @return Lista com todos os times do banco
 *///from   ww w  .j a  va2s.c o  m
public List<Time> listarPorDataFundacao(Date dataIni, Date dataFin) {
    try {
        Session sessao = Hibernate4Util.getSessionFactory();
        Transaction transacao = sessao.beginTransaction();
        Query consulta = sessao.createQuery(
                "from Time where dataFundacao between :dataini AND :datafin order by dataFundacao desc, codigo");
        consulta.setDate("dataini", dataIni);
        consulta.setDate("datafin", dataFin);

        List<Time> resultado = consulta.list();
        transacao.commit();
        return resultado;
    } catch (HibernateException e) {
        System.out.println("No foi possvel selecionar times. Erro: " + e.getMessage());
        throw new HibernateException(e);
    }
}

From source file:dao.TimeDao.java

public List<Time> listarTimesPorJogo(Jogo jogo) {
    try {//  w  w w .ja v a2  s . co m
        if (jogo == null) {
            return null;
        }

        Session sessao = Hibernate4Util.getSessionFactory();
        Transaction transacao = sessao.beginTransaction();
        Query consulta = sessao
                .createQuery("SELECT ti1 " + " FROM Jogo jo" + " JOIN jo.time1 ti1" + " WHERE (jo = ?)");
        consulta.setEntity(0, jogo);
        List<Time> resultado = consulta.list();
        consulta = sessao
                .createQuery("SELECT ti1 " + " FROM Jogo jo" + " JOIN jo.time2 ti2" + " WHERE (jo = ?)");
        consulta.setEntity(0, jogo);
        resultado.addAll(consulta.list());
        transacao.commit();
        return resultado;
    } catch (HibernateException e) {
        System.out.println("No foi possvel selecionar apostadores. Erro: " + e.getMessage());
        throw new HibernateException(e);
    }
}

From source file:DatosPersistentes.AccesoDatos.java

protected void manejarExcepcionHibernate(HibernateException excepcionHibernate) throws HibernateException {
    transaccion.rollback();/*w ww .  java  2s . co  m*/
    throw new HibernateException("No se pudo realizar la transaccion");
}

From source file:de.bstreit.java.oscr.business.base.finance.money.MoneyType.java

License:Open Source License

@Override
public Object deepCopy(Object value) throws HibernateException {

    if (value == null) {
        return null;
    }// w  w  w .  j a v a  2 s .co m

    if (!(value instanceof Money)) {
        throw new HibernateException("value is not of type Money!");
    }

    final Money money = (Money) value;
    return new Money(money.getAmount(), money.getCurrency());
}

From source file:de.cosmocode.hibernate.ReverseIlikeExpression.java

License:Apache License

@Override
public String toSqlString(Criteria criteria, CriteriaQuery criteriaQuery) throws HibernateException {
    final SessionFactoryImplementor factory = criteriaQuery.getFactory();
    final Dialect dialect = factory.getDialect();
    final String[] columns = criteriaQuery.getColumnsUsingProjection(criteria, propertyName);

    if (columns.length != 1)
        throw new HibernateException("ilike may only be used with single-column properties");

    final String columnName = columns[0];
    final String s = matchMode.toMatchString(factory, columnName);

    if (dialect instanceof PostgreSQLDialect) {
        return "? ilike " + s;
    } else {/*ww w  . jav a 2  s . c om*/
        return "? like " + dialect.getLowercaseFunction() + "(" + s + ")";
    }

}