|
From: Tim K. <tim...@gm...> - 2006-03-14 19:13:43
|
I was punting around this for a good while before taking five minutes to look at the source for the LocalSessionFactoryBean and having one of those 'oh-doh' moments. I now feel that the javadocs for those methods are misleading. What I was working on was a setup module for our webapp that would create/initialize the schema via a web-based UI.. and was using the LSFB methods to facilate that functionality. What I wanted to do was trap any exceptions that arose from the schema methods so that they could be displayed on the UI if there was a schema creation error. Looking at the javadocs for those schema methods, in particular the 'Throws' part in the javadoc where it says 'DataAccessException - in case of script execution errors' it seemed natural to assume that catching DataAccessException would do the trick. But no matter how many sacrifical lambs i put up, I was unable to trap *any* kind of exception, even though I could see the exception output in the logs. I was starting to question my competence as a programmer and my sanity. So after looking thru the source for the LSFB, I see that those schema methods call the 'executeSchemaStatement' and 'executeSchemaScript' methods internally. And to their credit to some degree, the javadocs for those methods do mention this: "Note that the default implementation will log unsuccessful statements and continue to execute. Override the executeSchemaStatement method to treat failures differently." So THAT explains why I wasn't able to trap the exception being thrown, and was seeing them in the logs. Simply by looking at the javadocs by itself, a programmer (or at least a simple one like me) wouldn't immediately make the association that those schema methods would call the executeSchemaStatements internally and that any schema errors would be logged and that DAE would not be thrown at all. That was only obvious after looking at the source code. So it would seem that my only option is to subclass LSFB and modify the behavior of those to collect the error messages and pass them on up. I would think, however that those methods could benefit from clearer javadoc comments on what I've just covered, and it would be nice to be able to obtain that output (or to at least know somehow) to be able to determine if any errors were generated, and have some sort of output on the reasons why, since there is no way to accomplish that right now without subclassing the LSFB itself (as far as I can see) - and I'm somewhat leery of having to maintain a subclass of LSFB for the entire foreseeable future of the application since it is such a critical part of the spring/hibernate functionality. If I'm mistaken on this, I'd greatly appreciate a point in the right direction. Also, slightly related, but is there a reason why 'updateDatabaseSchema' throws HibernateException while the other two 'create'/'dropDatabaseSchema' methods throw DataAccessException? Thanks! -tim |