コード例 #1
0
  @GET
  public List<Atendimento> get(
      @DefaultValue("0") @QueryParam("start") int start,
      @DefaultValue("6") @QueryParam("limit") int limit)
      throws Exception {

    if (limit < 1 || limit > 100) {
      throw new Exception("O limite deve estar entre 1 e 100");
    }
    System.out.println(em);
    return em.createQuery("SELECT a FROM Atendimento a", Atendimento.class)
        .setFirstResult(start)
        .setMaxResults(limit)
        .getResultList();
  }
コード例 #2
0
 @GET
 @Path("/getclients")
 @Produces("application/json; charset=utf-8")
 // http://localhost:8080/ProjetRestFull/eources/getjson
 public JResponse getEtudiantToJSONText() throws ParseException {
   EntityManager em = HibUtil.getEntityManager();
   em.getTransaction().begin();
   List<Client> clis = em.createQuery("from Client").getResultList();
   Hibernate.initialize(clis);
   for (Client c : clis) {
     // On met le séjour à null, sinon il y a des références circulaires.
     em.detach(c);
     c.setSejours(null);
   }
   GenericEntity<List<Client>> entity = new GenericEntity<List<Client>>(clis) {};
   JResponse r = JResponse.ok(entity).build();
   em.getTransaction().commit();
   HibUtil.closeEntityManager();
   return r;
 }