|Re: debug-mode: reload the xml files from the disk for each request||Larry Meadors||8/14/12 6:50 AM|
Write a unit test.
On Tue, Aug 14, 2012 at 3:57 AM, Christof <doll.c...@googlemail.com> wrote:
> Hi there,
> in my current project I frequently deal with minor changes concerning the sql statements. After changing a statement I restart the application server in order to rebuild the mappers from the xml files. However, this is time consuming and annoying.
> I would like the mappers to be automatically rebuilt after changing an xml file or upon each http request or ...
> What's the best way to achieve this?
> Best regards,
|Re: debug-mode: reload the xml files from the disk for each request||Guy Rouillier||8/14/12 2:02 PM|
Having MyBatis watch the XML file for timestamp changes and
automatically update the in-memory maps would be great. However,
remember that MyBatis reads the XML files using the classpath, so it
doesn't really know where they are in order to monitor them. It could
figure that out, though.
But if you are content with rereading them with every request, then you
can rebuild your SqlSessionFactory like you do on startup. Sounds like
an inefficient approach, though, since 99% of the time you are not
updating the XML files. So, in your reread logic, keep a last-read
timestamp; then, at predetermined intervals (say every 5 minutes),
either blindly reread or manually check the file timestamps to see if
they changed and if so, reread them.
This would be a nice feature. I'd suggest opening an enhancement request.
|Re: debug-mode: reload the xml files from the disk for each request||Stephen Friedrich||8/14/12 2:23 PM|
Yes, we had implemented very much what Guy suggested in a project that used only core mybatis with the seam framework for dependency injection.
The solution was two-fold:
1) Recreate the session factory when needed. This was easy, because our own code explicitly created and injected the session factory
2) Reload the mapper xml files for each new session factory: Core mybatis allows to set a class loader that it uses to load resources. We supplied our own that always used newest available xml file versions.
However currently we are using the mabtis-guice integration and neither issue can be solved as easily:
1) mybatis-guice creates the session factory behind the scenes. How can we tell it to create a new one (and re-read the configuration files while doing so)?
2) It seems mybatis-guice does not use the specified classloader for loading xml mapper files. How do we prevent caching (or better update the files only when needed)?