griffon-plugins / griffon-mybatis-plugin

Griffon MyBatis Plugin
http://griffon-framework.org/
Apache License 2.0
1 stars 1 forks source link

Connection Pooling timeout doesn't rerun Bootstrap on new Connection #2

Closed swalton00 closed 4 years ago

swalton00 commented 4 years ago

In MyBatis Bootstrap I issue an H2 "Set Schema" so I can omit the schema from the SQL (and change environments by changing Schemas). The problem is that if the application is idle for a short time, the Connection passes its idle timeout and is closed. When a new connection is opened, the set schema is not reissued, so the next SQL statement fails.

I can see several possible approaches to fixing this: the simplest is to eliminate the connection pooling entirely and simple create one (long-term) connection and closing it during shutdown. As a DBA, I'm in favor of this because, if every desktop app opened 5 connections (the current default), the database would quickly run out of connections. As the code is currently written, it is extremly unlikely that the application could ever use two connections, let alone five. A second approach could be to issue the Bootstrap every time a connection is opened. And still another approach would be to provide a "pre-SQL" to be issued prior to every MyBatis statement.

The net result of this issue is that SQL statements work for a period of time, and then, after an idle period, they all fail (even ones that were succesfully issued a short time before).

swalton00 commented 4 years ago

I can work around this by setting the Schema in the URL (append ";SCHEMA=RR" to the URL)

swalton00 commented 4 years ago

This is working as it should be - to allow creation of tables on the first connection.