Ok, so this one is frankly odd as far as I'm concerned.
I have a simple java application that reads a load of xml files and then populates the database. The problem is that when saveOrUpdate is called, the database doesn't get populated properly - HSQLDB database log file is incomplete and looks corrupted as if the JVM terminated half way through the transaction commit.
I'm using Spring 2.0.8 with AOP transaction management which I've used before with no problem. Here's the code:
Code:
public void uploadFormsToDB() {
Session session = sessionFactory.getCurrentSession();
IFormMetaData ifmd = (IFormMetaData) session.createQuery("from IFormMetaData as ana where ana.name=:name").setString("name", "sja").uniqueResult();
log.info("Files to be processed: " + files.size());
for (String filePath : files) {
try {
log.info("Processing file: " + filePath);
SJABean sja = new SJABean(); // The SJA to be populated
sja.getForm().setTimezoneoffset(0L);
handler.setSja(sja);
handler.setFilePath(filePath);
handler.setIfmd(ifmd);
xmlReader.setContentHandler(handler);
xmlReader.parse(filePath);
session.saveOrUpdate(sja.getForm());
} catch (Exception e) {
log.warn("Processing interrupted. " + e.getMessage(), e);
}
}
log.info("Form import save started");
}
sja.getForm returns the object to be saved to the db, it is formatted correctly with all the various fields populated. SaveOrUpdate executes with no problem - at least there're no exceptions.
The transaction config for this method is within spring:
Code:
<aop:config>
<aop:pointcut id="importerMethods" expression="execution(* com.sms.iforms2.sjaimporter.ProcessForms.*(..))"/>
<aop:advisor advice-ref="txAdviceimport" pointcut-ref="importerMethods"/>
</aop:config>
<tx:advice id="txAdviceimport" transaction-manager="txManager">
<tx:attributes>
<tx:method name="*" propagation="REQUIRED"/>
</tx:attributes>
</tx:advice>
with the above method within ProcessForms.
The really bizzare thing is that if i step through the code with the debugger, occasionally the database will be written out correctly! This is a single threaded application so unless Hibernate or the HSQLDB jdbc driver utilises Threads I don't see how this can happen....
The application terminates once this method is completed.
I would Really appreciate any pointers on this as I've never come across this behaviour before - used to usual Hibernate exceptions ;-)