if(!dao.getImplementationObject().isAutoSQLGeneration()){ //'isAutoSQLGeneration()' was simply used for flagging whether a transaction listener has been attached.
final IDAO finalDAO = dao;
dao.set(getCorrelationFieldName(), ((EJBProcessInstance)instance).getProcessInstanceDAO().get(getCorrelatedFieldName()));
instance.getProcessTransactionContext().addTransactionListener(new TransactionListener(){
public void beforeCommit(TransactionContext tx) throws Exception {
finalDAO.getImplementationObject().setTableName(getTableName());
finalDAO.getImplementationObject().setSqlStmt(null);
finalDAO.getImplementationObject().setAutoSQLGeneration(true);