Am using Hibernate with MySQL Database in a web application project, mainly using JSF, after I change data in the database manually and committing, Hibernate doesn't detect these changes, and hibernate queries returns same old results, not until I restart the application, the changes becomes detectable. I disabled second level cache but still.
public List<Property> findAll() {
try {
session = DBUtils.openSession();
List<Property> resultList = (List<Property>) session.createCriteria(Property.class).add(Restrictions.eq("active", new Integer(1))).list();
DBUtils.closeSession(session);
return resultList;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
public class DBUtils {
public static Configuration config;
public static SessionFactory factory;
static {
try {
config = new Configuration();
config.configure();
StandardServiceRegistryBuilder ssrb = new StandardServiceRegistryBuilder().applySettings(config.getProperties());
factory = config.buildSessionFactory(ssrb.build());
} catch (Exception ex) {
ex.printStackTrace();
} finally {
if (input != null) {
try {
input.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
public static SessionFactory getSessionFactory() {
return factory;
}
public static Session openSession() {
try {
return getSessionFactory().openSession();
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
public static boolean closeSession(Session session) {
try {
if (session != null && session.isOpen()) {
session.close();
}
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
}