private static void readRole(String roleId) {
logger.info("readRole");
EntityManager em = EMF.createEntityManager();
EntityTransaction tx = em.getTransaction();
try {
tx.begin();
Role role = em.find(Role.class, roleId);
logger.info("role id: {}", role.getId());
for (String perm : role.getPermissions()) {
logger.info("perm: {}", perm);
}
tx.commit();
} catch (Exception ex) {
tx.rollback();
throw ex;
} finally {
em.close();
}
}
- FetchType.EAGER -> 한방쿼리 -> 객체에서 getPermission()해도 아무일도 안일어남
select r1_0.id,r1_0.name,p1_0.role_id,p1_0.perm from role r1_0 left join role_perm p1_0 on r1_0.id=p1_0.role_id where r1_0.id=?
- FetchType.LAZY -> 나눠서 쿼리 -> 객체.getPermission() 하면 쿼리 호출 와우
select r1_0.id,r1_0.name from role r1_0 where r1_0.id=?
select p1_0.role_id,p1_0.perm from role_perm p1_0 where p1_0.role_id=?