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.
On 8/14/2012 5:57 AM, Christof 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, Christof
>
--
Guy Rouillier