[英]What does NHibernate.AssertionFailure on doing transaction.Commit() mean?
I am a newbie to programming Windows forms application. I am stuck with an error for the past 2 days. I had a method
I am a newbie to programming Windows forms application. I am stuck with an error for the past 2 days. I had a method
在基础DAO层中I am a newbie to programming Windows forms application. I am stuck with an error for the past 2 days. I had a method
Add()`
public virtual void Add(T entity)
{
try
{
DomainObject domObj = entity as DomainObject;
if (domObj != null)
{
domObj.CreatedDate = domObj.LastModifiedDate = DateTime.Now.ToUniversalTime();
}
using (ITransaction transaction = GetTransaction)
{
_session.Save(entity);
//******* _session.SaveOrUpdate(entity);
// _session.Refresh(entity);
//transaction.Commit();
}
}
我试图将transaction.Commit()
移到Base DAO层中的单独方法中。
public virtual void Commit(T entity)
{
using (ITransaction transaction = GetTransaction)
{
transaction.Commit();
}
}
我已经在其余各层中进行了相应的更改。 现在,当我运行该应用程序并将数据输入表单时,我遇到了此异常(NHibernate.AssertionFailure)。 请帮忙。
这是MarketScenario实体类代码:
namespace RKG.SCM.ModelObjects
{public class MarketScenarioModel {public MarketScenarioModel(){}
public MarketScenarioModel(string selectedMarketIds)
{
this.MarketIdList = selectedMarketIds;
}
public virtual int Id { get; set; }
public virtual ScenarioModel ScenarioModel { get; set; }
public virtual string MarketIdList { get; set; }
}
这是MarketScenario NHibernate映射:
命名空间RKG.SCM.NHibernate.Mappings {
public class MarketScenarioMap : ClassMap<MarketScenario> {
public MarketScenarioMap() {
Table("market_scenario");
LazyLoad();
Id(x => x.Id).GeneratedBy.Identity().Column("id");
References(x => x.Scenario).Column("scenario_id");
Map(x => x.MarketIdList).Column("market_id_list");
}
}
}
如果可以显示MarketScenario实体类代码及其映射(xhbm或fluent或您使用的任何格式),将很有帮助。
看起来其主键不是身份(自动生成),并且您尝试保存具有空ID的对象。 如果它是一个标识列,那将是可以的。
当然,这取决于您要使用哪种身份生成策略。 我认为您应该告诉我们更多有关此实体及其标识列的信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.