无法更新/插入数据到数据库这是我的表:
角色(ID、姓名、...)
特权(ID、姓名、...)
RolePrivilege(Id、RoleId、PrivilegeId、IsAllowed)
我有地图:
public class RoleWithPrivilegesEntityMap : ClassMap<RoleWithPrivilegesEntity>
{
public RoleWithPrivilegesEntityMap()
{
Table( "ROLE" );
Not.LazyLoad();
Id( x => x.Id, "ID" ).GeneratedBy.Identity();
Map( x => x.Name, "NAME" ).Not.Nullable().Length( 100 );
HasMany(x => x.RolePrivileges)
.Cascade.AllDeleteOrphan()
.Inverse()
.Fetch.Join().KeyColumn("RoleId");
}
}
public class PrivilegeEntityMap : ClassMap<PrivilegeEntity>
{
public PrivilegeEntityMap()
{
Table("PRIVILEGE");
Id(x => x.Id, "ID").GeneratedBy.Identity();
Map(x => x.Name, "NAME").Not.Nullable();
HasMany(x => x.RolePrivileges)
.Cascade.AllDeleteOrphan()
.Inverse()
.Fetch.Join().KeyColumn("PrivilegeId");
}
}
public class RolePrivilegeEntityMap : ClassMap<RolePrivilegeEntity>
{
public RolePrivilegeEntityMap()
{
Table("ROLEPRIVILEGE");
Id(x => x.Id, "R_ID").GeneratedBy.Identity();
Map(x => x.IsAllowed, "ISALLOWED").Not.Nullable();
References(x => x.Role)
.Not.Nullable()
.Column("R_ID");
References(x => x.Privilege)
.Not.Nullable()
.Column("P_ID");
}
}
我正在尝试更新现有记录
session.SaveOrUpdate(rolePrivilege)
数据库使插入表 RolePrivilege,但我需要首先删除记录。
我究竟做错了什么?