Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version:
Version 2.1
Name and version of the database you are using:
Mysql 4.1.8
Code between sessionFactory.openSession() and session.close():
Adapter adapter = Adapter.getAdapter();
AuditLogInterceptor interceptor = new AuditLogInterceptor();
Session s = openHibernateSession(interceptor);
try {
interceptor.setSession(s);
interceptor.setUserId(ctx.getCallerPrincipal().getName());
interceptor.setTargetName(adapter.getAdapterId());
Set configs = adapter.getParams();
adapter.setParams(new HashSet());
// Save Adapter Object
s.save(adapter);
s.flush();
// Save Adapter Parameters
Iterator it = configs.iterator();
while (it.hasNext()) {
config = (AdapterParam) it.next();
config.setAdapter(adapter);
s.save(config);
}
s.flush();
}
catch (Exception e) {
throw new EJBException(e);
}
finally {
closeHibernateSession(s);
}
// In the Interceptor, the code is as following
public void postFlush(Iterator iterator) throws CallbackException {
try {
Class.forName("org.gjt.mm.mysql.Driver");
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306","user","password");
PreparedStatement ps = conn.prepareStatement("SELECT * FROM ADAPTER WHERE ADAPTER_ID = \'testPostFlush\'");
ResultSet rs = ps.executeQuery();
if (rs.next()) {
logger.info("ADAPTER \'testPostFlush\' EXISTS IN DB!!");
} else {
logger.info("ADAPTER \'testPostFlush\' DOES NOT EXIST IN DB!!");
}
} catch (Exception e) {
e.printStackTrace();
}
}
Full stack trace of any exception that occurs:
When I run my code, in the interceptor I get "ADAPTER 'testPostFlush' DOES NOT EXIST IN DB!!". I think it proves the data is not infact flushed to the database as it should be when I invoke the method "s.flush()". I am relying on the data to actually be flushed to the database immediately after invoking "s.flush()" for a function I wish to implement in the postFlush() method.
Anyone have same problem or any suggestions?
Is this a Hibernate 2.1 bug?