nhibernate:composite-id class must override Equals()
2012-01-31 18:37
573 查看
当使用NHibernate查询表中的数据时,如果表中存在复合主键,如果没有在相应的实体类中重写Equals(),那么将会出现"Could not compile the mapping document:
TestCleanSnow.JkptGlxtUser.hbm.xml".当跟踪出错的内部信息的时候会发现,内部异常为"composite-id class must override Equals(): TestCleanSnow.JkptGlxtUserId"
解决办法:
在JkptGlxtUserId.cs这个实体类中重写Equals()方法如下:
public override bool Equals(object obj)
{
return base.Equals(obj);
}
复制代码
再次执行调用语句,发现还出现"Could not compile the mapping document: TestCleanSnow.JkptGlxtUser.hbm.xml".这个错误,但是跟踪内部异常为:InnerException = {"composite-id class must override GetHashCode(): TestCleanSnow.JkptGlxtUserId"}
到此很明显,在遇到复合主键的情况下,应该还得在JkptGlxtUserId.cs中重写GetHashCode(),代码如下:
public override int GetHashCode()
{
return base.GetHashCode();
}
复制代码
再次运行调用程序,OK了.
TestCleanSnow.JkptGlxtUser.hbm.xml".当跟踪出错的内部信息的时候会发现,内部异常为"composite-id class must override Equals(): TestCleanSnow.JkptGlxtUserId"
解决办法:
在JkptGlxtUserId.cs这个实体类中重写Equals()方法如下:
public override bool Equals(object obj)
{
return base.Equals(obj);
}
复制代码
再次执行调用语句,发现还出现"Could not compile the mapping document: TestCleanSnow.JkptGlxtUser.hbm.xml".这个错误,但是跟踪内部异常为:InnerException = {"composite-id class must override GetHashCode(): TestCleanSnow.JkptGlxtUserId"}
到此很明显,在遇到复合主键的情况下,应该还得在JkptGlxtUserId.cs中重写GetHashCode(),代码如下:
public override int GetHashCode()
{
return base.GetHashCode();
}
复制代码
再次运行调用程序,OK了.
相关文章推荐
- NHibernate composite-id class must override Equals() 解决办法
- Nhibernate composite-id class must override Equals()解决办法
- NHibernate composite-id class must override Equals() 解决办法
- NHibernate composite-id class must override Equals() 解决办法 分类: 技术心得(C#与JAVA) 2013-01-23 15:20 1289人阅
- composite-id class must implement Serializable
- one-to-one with composite-id must have common CompositeId class
- 联合主键配置时忽略的问题composite-id class must implement Serializable
- composite-id class must implement Serializable
- NHibernate Issues之1255:联合主键(composite-id)
- org.hibernate.id.IdentifierGenerationException: ids for this class must be manually assigned before
- org.hibernate.id.IdentifierGenerationException: ids for this class must be manually assigned before
- NHibernate Issues之1255:联合主键(composite-id)
- Hibernate报错:org.hibernate.id.IdentifierGenerationException:ids for this class must be manually assigned before calling save()
- org.hibernate.id.IdentifierGenerationException: ids for this class must be manually assigned before calling
- Hibernate报错:org.hibernate.id.IdentifierGenerationException:ids for this class must be manually assig
- org.hibernate.id.IdentifierGenerationException: ids for this class must be manually assigned before
- org.hibernate.id.IdentifierGenerationException: ids for this class must be manually assigned before calling save():
- Java Web编程入门--错误信息“The method getUserById(int) of type UserServiceImpl must override a superclass”
- NHibernate 联合主键(composite-id)
- message ids for this class must be manually assigned before calling save(): ID 的问题