I have a class that extends DescriptorEventAdapter and implements SessionCustomizer and DescriptorCustomizer.
I have override the postWrite and postDelete methods to obtain the SQL statements and store them into a separate database. On some of the objects that gets stored, the SQL returned is null, but the object was inserted.
How can I ensure that the SQL string is always returned?
public class SQLLogger extends DescriptorEventAdapter implements SessionCustomizer, DescriptorCustomizer {
@Override
public void customize(ClassDescriptor descriptor) throws Exception {
descriptor.getEventManager().addListener(this);
}
@Override
public void customize(Session session) throws Exception {
for (ClassDescriptor descriptor : session.getDescriptors().values()) {
customize(descriptor);
}
}
@Override
public void postWrite(DescriptorEvent event) {
processDescriptorEvent(event);
}
@Override
public void postDelete(DescriptorEvent event) {
processDescriptorEvent(event);
}
protected void processDescriptorEvent(DescriptorEvent descriptorEvent) {
String sql = descriptorEvent.getQuery().getTranslatedSQLString(descriptorEvent.getSession(), descriptorEvent.getQuery().getTranslationRow());
//store sql into auditing database
}