Nhibernate transaction issue when moving to mysql from mssql
I was originally using Nhibernate with MSSQL (2008) and everything worked great. I had a web app which bound a session per request and wrapped every unit of work within a transaction. The transactions were injected via AOP and a custom attribute, so everything with the required attribute would b开发者_运维问答e wrapped in a transaction that either ended with a commit or a rollback.
Again just to clarify everything was working fine in MSSQL and using Nhibernate Profiler I can see that all the transactions are occurring as expected.
Now I have just added support for Mysql (5.1) (as one environment uses a Mysql db), I have setup all the tables as InnoDB and the table structures are all identical, so I am a bit baffled as to why I get the following error:
Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect): [SomeRandomEntity#1]Could not synchronize database state with session
Checking on Nhibernate profiler, it is beginning a transaction, firing an update call then bombing out with the error, whereas really it should be committing at that point.
If it helps the sql being fired in the update is (names changed):
UPDATE
some_table SET some_column_1 = 1230697028 /* ?p0 */,
some_column_2 = '2011-07-21T10:58:59.00' /* ?p1 */
WHERE some_column_3 = 1 /* ?p2 */
It is also worth noting that I am not using any Isolation Level on my transactions, I wasnt sure which one would be best for my setup and Mssql didnt complain when I didnt set it.
Has anyone seen any issues like this before, as it is a show stopper at the moment :(
=== Edit ===
Incase it helps here is my connection string:
<connectionStrings>
<add name="NHibernateConnection" connectionString="Server=localhost;Database=xxxxx;Uid=root;" providerName="System.Data.SqlClient"/>
</connectionStrings>
It seems the problem was down to a wonky column that was not inserting somewhere else, which was stopping the update. Although the error was not really clear as to what the underlying problem was.
精彩评论