NHibernate的Session.Flush()发送更新查询时没有更新已发生发生、NHibernate、Session、Flush

2023-09-03 09:55:46 作者:岁月如歌

我有一个NHibernate会话。在本届会议上,我完全执行1操作,这是运行此code,以获取列表:

I have an NHibernate session. In this session, I am performing exactly 1 operation, which is to run this code to get a list:

public IList<Customer> GetCustomerByFirstName(string customerFirstName)
{
return _session.CreateCriteria(typeof(Customer))
    .Add(new NHibernate.Expression.EqExpression("FirstName", customerFirstName))
    .List<Customer>();
}

我打电话 Session.Flush()在的的Htt prequest ,并最终我获得 HibernateAdoException 。 NHibernate的是通过一个更新语句的分贝,并导致外键冲突。如果我不跑了刷新,请求完成没有问题。这里的问题是,我需要冲洗到位的情况下有出现其他场次内的变化,因为这code在其他地区重新使用。难道还有其他的配置设置,我可能会丢失?

I am calling Session.Flush() at the end of the HttpRequest, and I get a HibernateAdoException. NHibernate is passing an update statement to the db, and causing a foreign key violation. If I don't run the flush, the request completes with no problem. The issue here is that I need the flush in place in case there is a change that occurs within other sessions, since this code is reused in other areas. Is there another configuration setting I might be missing?

下面是从异常的code:

Here's the code from the exception:

[SQL: UPDATE CUSTOMER SET first_name = ?, last_name = ?, strategy_code_1 = ?, strategy_code_2 = ?, strategy_code_3 = ?, dts_import = ?, account_cycle_code = ?, bucket = ?, collector_code = ?, days_delinquent_count = ?, external_status_code = ?, principal_balance_amount = ?, total_min_pay_due = ?, current_balance = ?, amount_delinquent = ?, current_min_pay_due = ?, bucket_1 = ?, bucket_2 = ?, bucket_3 = ?, bucket_4 = ?, bucket_5 = ?, bucket_6 = ?, bucket_7 = ? WHERE customer_account_id = ?]

没有参数显示为传递。

推荐答案

我已经在我的车型之一没有正确映射(不使用可空类型正确)之前见过这一次。愿你请粘贴模型和映射?

I have seen this once before when one of my models was not mapped correctly (wasn't using nullable types correctly). May you please paste your model and mapping?