Example usage for org.hibernate Session get

List of usage examples for org.hibernate Session get

Introduction

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

Prototype

Object get(String entityName, Serializable id);

Source Link

Document

Return the persistent instance of the given named entity with the given identifier, or null if there is no such persistent instance.

Usage

From source file:br.com.bean.RestControllers.alunoController.java

public static Aluno buscaAlunoParaOperacao(long id) throws HibernateException {
    Session sessao = HibernateUtility.getSession();
    try {//www .  j  av a2s.  c  om
        Aluno a = (Aluno) sessao.get(Aluno.class, id);
        return a;
    } catch (HibernateException e) {

    } finally {
        sessao.close();
    }
    return null;
}

From source file:br.com.bean.RestControllers.faculdadeController.java

@RequestMapping(value = "buscaPorId-faculdade", method = RequestMethod.GET)
public String get(long id) throws HibernateException {
    Session sessao = HibernateUtility.getSession();
    try {//from   www  .  j  a  va  2s  .co m
        Faculdade f = (Faculdade) sessao.get(Faculdade.class, id);
        Gson gson = new Gson();
        f.setTurmas(null);
        return gson.toJson(f, Faculdade.class);
    } catch (HibernateException e) {
        return CriadorJson.criaJsonErro(e, "Verificar");
    } finally {
        sessao.close();
    }
}

From source file:br.com.bean.RestControllers.faculdadeController.java

public static Faculdade buscaFaculdadeParaOperacao(long id) throws HibernateException {
    Session sessao = HibernateUtility.getSession();
    try {//from ww  w  .ja  v a  2  s .c o m
        Faculdade f = (Faculdade) sessao.get(Faculdade.class, id);
        return f;
    } catch (HibernateException e) {

    } finally {
        sessao.close();
    }
    return null;
}

From source file:br.com.bean.RestControllers.festaController.java

@RequestMapping(value = "buscaPorId-festa", method = RequestMethod.GET)
public String get(long id) throws HibernateException {
    Session sessao = HibernateUtility.getSession();
    try {// www. j a va  2  s  . c  om
        Festa f = (Festa) sessao.get(Festa.class, id);
        Gson gson = new Gson();
        return gson.toJson(f, Festa.class);
    } catch (HibernateException e) {
        return e.getMessage();
    } finally {
        sessao.close();
    }
}

From source file:br.com.bean.RestControllers.festaController.java

public static Festa buscaFestaParaOperacao(long id) throws HibernateException {
    Session sessao = HibernateUtility.getSession();
    try {//from  w  w  w  .ja  v  a 2 s. c o m
        Festa f = (Festa) sessao.get(Festa.class, id);
        return f;
    } catch (HibernateException e) {

    } finally {
        sessao.close();
    }
    return null;
}

From source file:br.com.bean.RestControllers.representanteController.java

@RequestMapping(value = "buscaPorId-representante", method = RequestMethod.GET)
public String get(long id) throws HibernateException {
    Session sessao = HibernateUtility.getSession();
    try {/*ww w.j  a  v a2s  .  c  o m*/
        Representante r = (Representante) sessao.get(Representante.class, id);
        Gson gson = new Gson();
        return gson.toJson(r, Representante.class);
    } catch (HibernateException e) {
        return CriadorJson.criaJsonErro(e, "Verificar");
    } finally {
        sessao.close();
    }
}

From source file:br.com.bean.RestControllers.representanteController.java

public static Representante buscaRepresentanteParaOperacao(long id) throws HibernateException {
    Session sessao = HibernateUtility.getSession();
    try {/*w w w .  j  a  v  a  2s  .  c om*/
        Representante r = (Representante) sessao.get(Representante.class, id);
        return r;
    } catch (HibernateException e) {

    } finally {
        sessao.close();
    }
    return null;
}

From source file:br.com.bean.RestControllers.turmaController.java

@RequestMapping(value = "buscaPorId-turma", method = RequestMethod.GET)
public String get(long id) throws HibernateException {
    Session sessao = HibernateUtility.getSession();
    try {//  www  . j a  va2s .  com
        Turma t = (Turma) sessao.get(Turma.class, id);
        Gson gson = new Gson();
        t.setFaculdade(null);
        return gson.toJson(t, Turma.class);

    } catch (HibernateException e) {
        return CriadorJson.criaJsonErro(e, "Verificar");
    } finally {
        sessao.close();
    }
}

From source file:br.com.bean.RestControllers.turmaController.java

public static Turma buscaTurmaParaOperacao(long id) throws HibernateException {
    Session sessao = HibernateUtility.getSession();
    try {//  w  w w.  j a v  a2 s  .  c om
        Turma t = (Turma) sessao.get(Turma.class, id);
        return t;
    } catch (HibernateException e) {

    } finally {
        sessao.close();
    }
    return null;
}

From source file:br.com.bean.RestControllers.usuarioController.java

@RequestMapping(value = "buscaPorId-usuario", method = RequestMethod.GET)
@ResponseBody//from w w  w  .  j a v  a  2  s .  com
public String get(long id) throws HibernateException {
    Session sessao = HibernateUtility.getSession();
    try {
        Usuario u = (Usuario) sessao.get(Usuario.class, id);
        Gson gson = new Gson();
        return gson.toJson(u, Usuario.class);
    } catch (HibernateException e) {
        return CriadorJson.criaJsonErro(e, "Algo Aconteceu, Verificar");
    } finally {
        sessao.close();
    }

}