I have to do the following in bold in my class to ensure that the flush happens. If I do not than I can not update ro delete. The explicit calls to s.setFlushMode(FlushMode.AUTO) and s.flush() needs to be made to ensure that updates and deletes can occur. I want to make sure is this right?
Code:
public static final ThreadLocal session = new ThreadLocal();
public static Session currentSession()
throws HibernateException {
Session s = (Session) session.get();
if (s == null) {
try {
SessionFactory sf = (SessionFactory) new InitialContext().lookup("java:hibernate/HibernateFactory");
s = sf.openSession();
[b]s.setFlushMode(FlushMode.AUTO);[/b]
session.set(s);
}
catch (Exception e) {
e.printStackTrace();
}
}
return s;
}
public static void closeSession() throws HibernateException {
Session s = (Session) session.get();
[b]s.flush();[/b]
session.set(null);
if (s != null) s.close();
}