I am using hibernate in dropwizard framework. Configuration of application: having a loadbalancer for the backend for multiple servers. The issue is when i am saving a new record, the records get saved in the database. But when i am trying to fetch the record from different server pointing to same database, i am not able to get the newly created row. It only exist in that server on which it was created. Hibernate cache are marked as false in the properties. Can anyone pls suggest what i am missing? or any tips.
Code :
Save api:
@Transactional
public ID save(T entity) {
EntityManager em = getEntityManager();
if (em.contains(entity) ) {
em.merge(entity);
} else {
em.persist(entity);
}
em.flush();
return (ID) entity.getId();
}
GET api:
public T findOne(final ID id) {
EntityManager em = getEntityManager();
T entity = em.find(getEntityClass(), id);
em.flush();
return entity;
}