Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

getting {"could not execute batch command.[SQL: SQL not available]"} error from NHibernate

I took a look at other related posts but couldn't find any solution.
Sometimes on sesstion.Flush() I get the following error:

{"could not execute batch command.[SQL: SQL not available]"}

and the Inner Exception :

{"The UPDATE statement conflicted with the FOREIGN KEY constraint FK1377052553ABF955. The conflict occurred in database ProcessDebug, table dbo.Adjustment, column 'AdjustmentId'.The statement has been terminated."}

a piece of Process class mapping :

   References(p => p.CurrentAdjustment)
        ;

    References(p => p.DefaultAdjustment)
        ;

    HasMany(p => p.Adjustments)
        .Cascade.AllDeleteOrphan()
        .Inverse()
        ;

All these properties above are of type of Adjustment. As long as I get this error once in a while I couldn't track it down. For an entity it might happen now, but not next time in a same piece of code....

Any idea what might cause the problem?
I'm using NH 3.2 and FluentNhibernate
Thanks in advance

like image 523
Javid_p84 Avatar asked Oct 09 '22 13:10

Javid_p84


2 Answers

In my situation, it was "NULL" in one of the databese columns. Check your database data.

FOREIGN KEY -> this means, that you propably have null i column, that is use for "join".

p.s. Take SQL Profiler and check the SQL generated by nHibernate.

like image 118
zchpit Avatar answered Oct 13 '22 11:10

zchpit


You need to look at the sql that is actually trying to execute.

It appears as though you are trying to update the primary key ("AdjustmentId") to something that does not exist. Hence the foreign key violation.

like image 29
Cole W Avatar answered Oct 13 '22 11:10

Cole W