0% found this document useful (0 votes)
46 views2 pages

Net Beans

This document contains code snippets for three methods that query a database: 1. The findUsuariosEntities method queries for users by role, catching any exceptions and closing the entity manager. 2. The findRolesEntities method queries for all roles or with pagination, closing the entity manager. 3. The findHabitacionesEntities method queries for all rooms or with pagination, closing the entity manager.

Uploaded by

Carolina Tobar
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
46 views2 pages

Net Beans

This document contains code snippets for three methods that query a database: 1. The findUsuariosEntities method queries for users by role, catching any exceptions and closing the entity manager. 2. The findRolesEntities method queries for all roles or with pagination, closing the entity manager. 3. The findHabitacionesEntities method queries for all rooms or with pagination, closing the entity manager.

Uploaded by

Carolina Tobar
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

usuarios public List<Usuarios> findUsuariosEntities(Roles rolusuario) { EntityManager em = getEntityManager(); try { Query q = em.createQuery("select u from Usuarios as u where u.

roles= :roles"); q.setParameter("rol", rolusuario);

return q.getResultList(); } catch (Exception ex) { ex.printStackTrace(); return null;

} finally { em.close(); } }

Rolcontroller private List<Roles> findRolesEntities(boolean all, int maxResults, int firstResult) { EntityManager em = getEntityManager(); try { Query q = em.createQuery("select r from Roles as r"); if (!all) { q.setMaxResults(maxResults); q.setFirstResult(firstResult);

} return q.getResultList(); } finally { em.close(); } } Habitacion private List<Habitaciones> findHabitacionesEntities(boolean all, int maxResults, int firstResult) { EntityManager em = getEntityManager(); try { Query q = em.createQuery("select h from Habitaciones as h"); if (!all) { q.setMaxResults(maxResults); q.setFirstResult(firstResult); } return q.getResultList(); } finally { em.close(); } }

You might also like