Transaction isolation levels in mybatis are defined in an enum with fixed isolation levels. This makes sense for most cases, but in JDBC the isolation levels are defined as an int because some databases support additional levels not defined in JDBC. For example, SQL Server has a "Snapshot" isolation level with a value of 0x1000 (4096) (link)

It would be nice if mybatis could add additional SqlSessionFactory.openSession methods that accept a custom transaction level in the form of an int instead of the traditional TransactionIsolationLevel enum.

Comment From: harawata

Thank you for the report, @maltalex ,

We should probably add SNAPSHOT to the TransactionIsolationLevel enum. We have a similar non-standard code support in JdbcType already. https://github.com/mybatis/mybatis-3/blob/c8f5a48de703786f23586e2b749e7323ed1f4cc7/src/main/java/org/apache/ibatis/type/JdbcType.java#L68

Comment From: maltalex

@harawata That will solve the immediate issue, but not the underlying one. What if some other database decides to encode SNAPSHOT to a different number? The SNAPSHOT enum will cause confusion, and will have to be renamed to SQL_SERVER_SNAPSHOT vs SOME_OTHER_DB_SNAPSHOT. Also, what if some other database decides to use 0x1000 for some other isolation level? We'll end up with two enums with the same value, which can also cause confusing bugs. Moreover, is Sql Server the only one with a custom transaction isolation level? I imagine there are more databases with weird isolation levels. Will mybatis just include all of them one by one as they're reported?

I feel like a better option would be to add a method for opening a session using an int isolation level, which is what happens on the JDBC level either way. The current methods that take an enum would be able to trivially call the one that takes an int.

Comment From: maltalex

One more thing - if you do decide to add a new SNAPSHOT enum just for Sql Server, it has to be clear to users that it's a transaction isolation level supported only by Sql Server. So it'll have to be named SQL_SERVER_SNAPSHOT or something similar. Otherwise, users might pass it to other databases by mistake.

Comment From: harawata

Hello @maltalex ,

I consult with other devs and we're going to add a new constant SQL_SERVER_SNAPSHOT to the TransactionIsolationLevel enum.

Regarding your concern about other drivers using 0x1000, it probably won't happen (driver devs will do the research, right?). And even if it happens, MyBatis users may still be able to use SQL_SERVER_SNAPSHOT as an alias (sort of).

Please let me know if you have any question or concern!

Comment From: maltalex

@harawata I would have preferred exposing the int, but adding a SQL_SERVER_SNAPSHOT enum is a perfectly acceptable solution as far as I'm concerned. Would you like me to submit a PR with this change?

Anyway, thank you for your work on mybatis.

Comment From: harawata

Hi again, @maltalex Yes, it would be great if you could submit a PR (no rush, of course). Thanks a lot for your contribution!

Comment From: maltalex

Done. Closing this issue.