No row with the given identifier exists

     org.hibernate.ObjectNotFoundException: No row with the given identifier exists:       [OfficeWH.entity.RoleRight#101]

 

     我在做一个关联表查询的时候,它报这个错误,请大家指正一下,这样的错误该怎样去解决!!有哪些情况会引发这一的错误呢!!一直报这个错误!!我估计是hibernate配置的关系有问题吧!!

下面有一张我数据库截图的图片,首先UserInfo表是用户登录,没问题!!   然后查出了SysRole表中  用户对应的角色,然后表关联到  RoleRight这个表,  根据这个角色查SysFun中对应的权限!!!

 

当然这个UserInfo还关联了其他的很多张表,它和RoInfo表配置的关系如下:   麻烦大家帮我看看,感激不尽!!!

  
      <class name="OfficeWH.entity.UserInfo" table="UserInfo" schema="dbo" catalog="MyOffice">
        <id name="userId" type="java.lang.String">
            <column name="UserId" length="50">
            <generator class="native">
        </id>
        <many-to-one name="userState" class="OfficeWH.entity.UserState" fetch="select">
            <column name="UserStateId" not-null="true">
        </many-to-one>
        //这里就是和  RoleInfo对应的关系配置文件
        <many-to-one name="roleInfo" column="RoleId" class="OfficeWH.entity.RoleInfo" fetch="select" lazy="false">
        </many-to-one>
        
        <property name="userName" type="java.lang.String">
            <column name="UserName" length="50" not-null="true">
        </property>
        <property name="password" type="java.lang.String">
            <column name="Password" length="50" not-null="true">
        </property>
        <property name="departId" type="java.lang.Integer">
            <column name="DepartId" not-null="true">
        </property>
        <property name="gender" type="java.lang.Integer">
            <column name="Gender" not-null="true">
        </property>
        <set name="fileInfos">
            <key>
                <column name="FileOwner" length="50" not-null="true">
            </key>
            <one-to-many class="OfficeWH.entity.FileInfo">
        </set>
        <set name="schedules">
            <key>
                <column name="CreateUser" length="50" not-null="true">
            </key>
            <one-to-many class="OfficeWH.entity.Schedule">
        </set>
        <set name="readCommonMessages">
            <key>
                <column name="UserId" length="50" not-null="true">
            </key>
            <one-to-many class="OfficeWH.entity.ReadCommonMessage">
        </set>
        <set name="manualSigns">
            <key>
                <column name="UserId" length="50" not-null="true">
            </key>
            <one-to-many class="OfficeWH.entity.ManualSign">
        </set>
        <set name="myNotes">
            <key>
                <column name="CreateUser" length="50" not-null="true">
            </key>
            <one-to-many class="OfficeWH.entity.MyNote">
        </set>
        <set name="loginLogs">
            <key>
                <column name="UserId" length="50" not-null="true">
            </key>
            <one-to-many class="OfficeWH.entity.LoginLog">
        </set>
        <set name="departInfos">
            <key>
                <column name="PrincipalUser" length="50" not-null="true">
            </key>
            <one-to-many class="OfficeWH.entity.DepartInfo">
        </set>
        <set name="messages">
            <key>
                <column name="FromUserId" length="50" not-null="true">
            </key>
            <one-to-many class="OfficeWH.entity.Message">
        </set>
        <set name="operateLogs">
            <key>
                <column name="UserId" length="50" not-null="true">
            </key>
            <one-to-many class="OfficeWH.entity.OperateLog">
        </set>
    </class>

 

RoleInfo表配置:

 

     <bag name="roleRights" table="RoleRight"  ="" order-by="NodeId asc">
            <key column="RoleId">
               
          
            <many-to-many class="OfficeWH.entity.RoleRight" column="NodeId">
        </bag>
        <bag name="userInfos" table="UserRole" inverse="true">
            <key column="RoleId">
               
          
            <many-to-many class="OfficeWH.entity.UserInfo">
        </bag>

 

RoleRight表配置:

 

  <many-to-one name="sysFun" class="OfficeWH.entity.SysFun" fetch="select">
            <column name="NodeId" length="50" not-null="true">
        </many-to-one>
        <many-to-one name="roleInfo" class="OfficeWH.entity.RoleInfo" fetch="select">
            <column name="RoleId" not-null="true">
        </many-to-one>

 

SysFun表配置:

 

  <set name="roleRights">
            <key>
                <column name="NodeId" length="50">
            </key>
            <many-to-many class="OfficeWH.entity.RoleRight" column="RoleId">
        </set>

 

1个回答

我没有仔细看你得配置文件,但是从这个异常
[code="java"]ObjectNotFoundException OfficeWH.entity.RoleRight#101[/code]
推断,应该是RoleRight表中不存在主键101数据造成的,hibernate的根据主键查询load时如果找不多记录就会报这个异常。

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐