Has anyone considered the case of using try-with-resources (Java SE 7) with Derby connections with auto-commit off?

I haven't studied this in detail, but from what I can see the above configuration will cause Connection.close to throw an exception if a transaction is active. Based on what the Java API docs say, I think Derby is behaving in a way that's allowed [1]. Nonetheless, this may not be what users expect.

I suppose one could work around this issue with an extra try-catch block, where you would call rollback/commit before rethrowing the exception, but this kind of defeats the purpose of try-with-resource.

Connection.close implements AutoClosable.close so we can't have two different behaviors for the two [2] scenarios (try-with-resources vs explicit close).

Have I missed something that makes this problem moot?


[1] "It is strongly recommended that an application explicitly commits or rolls back an active transaction prior to calling the close method. If the close method is called and there is an active transaction, the results are implementation-defined."
[2] Maybe one could use stack trace inspection, but that doesn't sound like a good solution.