У меня после REST службыПравильный способ закрыть Entity менеджера
public class myRestService {
@SuppressWarnings("unchecked")
@GET
@Path("")
@Produces(MediaType.APPLICATION_JSON)
public Response getApplications(
@QueryParam("Id") String Id) throws Exception {
EntityManager manager = HibernateUtil.getEntityManager();
EntityTransaction transaction = manager.getTransaction();
List<Application> applications = new ArrayList<Application>(0);
try {
transaction.begin();
Query query = manager.createQuery("select a from Application a where id= :Id");
query.setParameter("Id", Id);
applications = query.getResultList();
transaction.commit();
} catch (Exception e) {
e.printStackTrace();
} finally {
//manager.close();
}
return Response.ok(applications).build();
}
}
возвращающего заявления имеет инфинитив цикла, как показано ниже. Я предполагаю, что это происходит потому, что я не закрыл менеджера.
[{"name":"app1","id":1,"host":"http://www.app1.com","appType":"1","advertiser":{"name":"advertiser1","id":3,"status":"Inactive","applications":[{"name":"app1","id":1,"host":"http://www.app1.com","appType":"1","advertiser":
{"name":"advertiser1","id":3,"status":"Inactive","applications":......................
Если я закрою менеджер, я получу org.codehaus.jackson.map.JsonMappingException: failed to lazily initialize a collection of role: com.model.Advertiser.applications, could not initialize proxy -
. Я предполагаю, что это возникает из-за отсутствия сеанса связи.
пожалуйста, напишите код вашего класса сущностей '' Application' и advertiser' – Yogesh