Example usage for javax.persistence TransactionRequiredException getMessage

List of usage examples for javax.persistence TransactionRequiredException getMessage

Introduction

In this page you can find the example usage for javax.persistence TransactionRequiredException getMessage.

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:eu.freme.common.persistence.dao.DAO.java

public void flushAndClear() {
    try {//from w w w . j  a  v  a  2  s.  c  o m
        entityManager.flush();
        entityManager.clear();
    } catch (TransactionRequiredException e) {
        logger.warn("Tried to flush and clear the entity manager, but didn't work! (" + e.getMessage() + ")");
    }
}

From source file:mx.edu.ittepic.AEEcommerce.ejbs.OperationCommerce.java

public String updateCategory(String categoryid, String categoryname) {
    Message m = new Message();
    GsonBuilder builder = new GsonBuilder();
    Gson gson = builder.create();//  w w w  .  j a v a 2s.c  o m
    try {
        Category r = new Category();
        r = entity.find(Category.class, Integer.parseInt(categoryid));
        if (r == null) {
            m.setCode(404);
            m.setMsg("No se encontro");
            m.setDetail(":(");
        } else {
            r.setCategoryname(categoryname);
            entity.merge(r);
            m.setCode(200);
            m.setMsg("Todo bien");
            m.setDetail("OK");
        }
        return gson.toJson(m);
    } catch (IllegalArgumentException e) {
        m.setCode(404);
        m.setMsg(e.getMessage());
        m.setDetail("Error");
        return gson.toJson(m);
    } catch (TransactionRequiredException ex) {
        m.setCode(404);
        m.setMsg(ex.getMessage());
        m.setDetail("Error");
        return gson.toJson(m);
    }

}

From source file:mx.edu.ittepic.AEEcommerce.ejbs.OperationCommerce.java

public String updateCompany(String companyid, String companyname, String city, String country, String neigh,
        String zipcode, String state, String region, String street, String streetnumber, String phone,
        String rfc, String logo) {
    Message m = new Message();
    GsonBuilder builder = new GsonBuilder();
    Gson gson = builder.create();//from  w  w w  .  jav  a 2s  .  c o  m
    try {
        Company r = new Company();
        r = entity.find(Company.class, Integer.parseInt(companyid));
        if (r == null) {
            m.setCode(404);
            m.setMsg("No se encontro");
            m.setDetail(":(");
        } else {
            r.setCompanyname(companyname);
            r.setCity(city);
            r.setCountry(country);
            r.setNeighborhood(neigh);
            r.setZipcode(zipcode);
            r.setState(state);
            r.setRegion(region);
            r.setStreet(street);
            r.setStreetnumber(streetnumber);
            r.setPhone(phone);
            r.setRfc(rfc);
            r.setLogo(logo);
            entity.merge(r);
            m.setCode(200);
            m.setMsg("Todo bien");
            m.setDetail("OK");
        }
        return gson.toJson(m);
    } catch (IllegalArgumentException e) {
        m.setCode(404);
        m.setMsg(e.getMessage());
        m.setDetail("Error");
        return gson.toJson(m);
    } catch (TransactionRequiredException ex) {
        m.setCode(404);
        m.setMsg(ex.getMessage());
        m.setDetail("Error");
        return gson.toJson(m);
    }

}

From source file:mx.edu.ittepic.AEEcommerce.ejbs.OperationCommerce.java

public String deleteCompany(String CompanyId) {
    Message m = new Message();
    GsonBuilder builder = new GsonBuilder();
    Gson gson = builder.create();/*from ww w .  j  a v  a  2s  .co  m*/
    try {
        Company r = new Company();
        Query q = entity.createNamedQuery("Company.findByCompanyid").setParameter("companyid",
                Integer.parseInt(CompanyId));
        r = (Company) q.getSingleResult();
        if (r == null) {
            m.setCode(404);
            m.setMsg("No se encontro");
            m.setDetail(":(");
        } else {
            entity.remove(r);
            m.setCode(200);
            m.setMsg("Todo bien");
            m.setDetail("OK");
        }
        return gson.toJson(m);

    } catch (IllegalArgumentException e) {
        m.setCode(404);
        m.setMsg(e.getMessage());
        m.setDetail("error");
        return gson.toJson(m);
    } catch (NoResultException ex) {
        m.setCode(404);
        m.setMsg(ex.getMessage());
        m.setDetail("error");
        return gson.toJson(m);
    } catch (IllegalStateException exx) {
        m.setCode(404);
        m.setMsg(exx.getMessage());
        m.setDetail("error");
        return gson.toJson(m);
    } catch (TransactionRequiredException exxx) {
        m.setCode(404);
        m.setMsg(exxx.getMessage());
        m.setDetail("error");
        return gson.toJson(m);
    }
}

From source file:mx.edu.ittepic.AEEcommerce.ejbs.OperationCommerce.java

public String deleteUsers(String userid) {
    Message m = new Message();
    GsonBuilder builder = new GsonBuilder();
    Gson gson = builder.create();/*from   w  w w  .  ja va2s.  c  om*/
    try {
        Users r = new Users();
        Query q = entity.createNamedQuery("Users.findByUserid").setParameter("userid",
                Integer.parseInt(userid));
        r = (Users) q.getSingleResult();
        if (r == null) {
            m.setCode(404);
            m.setMsg("No se encontro");
            m.setDetail(":(");
        } else {
            entity.remove(r);
            m.setCode(200);
            m.setMsg("Todo bien");
            m.setDetail("OK");
        }
        return gson.toJson(m);

    } catch (IllegalArgumentException e) {
        m.setCode(404);
        m.setMsg(e.getMessage());
        m.setDetail("error");
        return gson.toJson(m);
    } catch (NoResultException ex) {
        m.setCode(404);
        m.setMsg(ex.getMessage());
        m.setDetail("error");
        return gson.toJson(m);
    } catch (IllegalStateException exx) {
        m.setCode(404);
        m.setMsg(exx.getMessage());
        m.setDetail("error");
        return gson.toJson(m);
    } catch (TransactionRequiredException exxx) {
        m.setCode(404);
        m.setMsg(exxx.getMessage());
        m.setDetail("error");
        return gson.toJson(m);
    }
}

From source file:mx.edu.ittepic.AEEcommerce.ejbs.OperationCommerce.java

public String deleteCategory(String categoryid) {
    Message m = new Message();
    GsonBuilder builder = new GsonBuilder();
    Gson gson = builder.create();/*from   w w  w.j  ava  2 s .co  m*/
    try {
        Category r = new Category();
        Query q = entity.createNamedQuery("Category.findByCategoryid").setParameter("categoryid",
                Integer.parseInt(categoryid));
        r = (Category) q.getSingleResult();
        if (r == null) {
            m.setCode(404);
            m.setMsg("No se encontro");
            m.setDetail(":(");
        } else {
            entity.remove(r);
            m.setCode(200);
            m.setMsg("Todo bien");
            m.setDetail("OK");
        }
        return gson.toJson(m);

    } catch (IllegalArgumentException e) {
        m.setCode(404);
        m.setMsg(e.getMessage());
        m.setDetail("error");
        return gson.toJson(m);
    } catch (NoResultException ex) {
        m.setCode(404);
        m.setMsg(ex.getMessage());
        m.setDetail("error");
        return gson.toJson(m);
    } catch (IllegalStateException exx) {
        m.setCode(404);
        m.setMsg(exx.getMessage());
        m.setDetail("error");
        return gson.toJson(m);
    } catch (TransactionRequiredException exxx) {
        m.setCode(404);
        m.setMsg(exxx.getMessage());
        m.setDetail("error");
        return gson.toJson(m);
    }
}

From source file:mx.edu.ittepic.AEEcommerce.ejbs.OperationCommerce.java

public String updateUsers(String userid, String username, String password, String phone, String neigborhood,
        String zipcode, String city, String country, String state, String region, String street, String email,
        String streetnumber, Part file, String cellphone, String companyid, String roleid, String gender) {
    Message m = new Message();
    GsonBuilder builder = new GsonBuilder();
    Gson gson = builder.create();/*ww  w .  jav  a2s.c om*/
    try {
        Users r = new Users();
        r = entity.find(Users.class, Integer.parseInt(userid));
        if (r == null) {
            m.setCode(404);
            m.setMsg("No se encontro");
            m.setDetail(":(");
        } else {
            r.setUsername(username);
            r.setPassword(password);
            r.setPhone(phone);
            r.setNeigborhood(neigborhood);
            r.setZipcode(zipcode);
            r.setCity(city);
            r.setCountry(country);
            r.setState(state);
            r.setRegion(region);
            r.setStreet(street);
            r.setEmail(email);
            r.setStreetnumber(streetnumber);

            r.setCellphone(cellphone);
            Company companyid_ = entity.find(Company.class, Integer.parseInt(companyid));
            Role roleid_ = entity.find(Role.class, Integer.parseInt(roleid));
            r.setCompanyid(companyid_);
            r.setRoleid(roleid_);
            r.setGender(gender.charAt(0));

            String nomArch = Paths.get(file.getSubmittedFileName()).getFileName().toString();
            if (!nomArch.equals("")) {
                PreExamenProduct updateU = new PreExamenProduct();
                r.setPhoto(updateU.updateImagenU(file, r.getUserid()));
            } else {

            }
            entity.merge(r);

            m.setCode(200);
            m.setMsg("Todo bien");
            m.setDetail("OK");
        }
        return gson.toJson(m);
    } catch (IllegalArgumentException e) {
        m.setCode(404);
        m.setMsg(e.getMessage());
        m.setDetail("Error");
        return gson.toJson(m);
    } catch (TransactionRequiredException ex) {
        m.setCode(404);
        m.setMsg(ex.getMessage());
        m.setDetail("Error");
        return gson.toJson(m);
    }

}