org.hibernate.ObjectNotFoundException: No row with the given identifier exists 解决办法

报错信息:

org.hibernate.event.internal.DefaultLoadEventListener onLoad
INFO: HHH000327: Error performing load command : org.hibernate.ObjectNotFoundException: No row with the given identifier exists: [com.weixin.db.model.Adminusers#15]

报错分析:

Hibernate的映射文件,表A里关联了表B的主键,当查询表A时,在B表里找不到对应记录时就会报错,如果只是逻辑删除不会报这种错误,只有当表B里测试没有id为15的这条数据了才会报错(已实际测试过);上面报错信息实体类后面【#15】表示实体类对应表id=15的记录找不到。也就是存在垃圾数据,可能是因为没有连带删除。

 

解决办法:

1. 修改配置文件加上 not-found="ignore" ”

即:

<many-to-one name="adminusers" class="com.weixin.db.model.Adminusers"
     fetch="select" lazy="false" not-found="ignore">
<p><span style="color: #ff0000;"><strong><span style="font-size: x-small;">     org.hibernate.ObjectNotFoundException: No row with the given identifier exists:       [OfficeWH.entity.RoleRight#101]</span> </strong> </span> </p> <p> </p> <p>     我在做一个关联表查询的时候,它报这个错误,请大家指正一下,这样的错误该怎样去解决!!有哪些情况会引发这一的错误呢!!一直报这个错误!!我估计是hibernate配置的关系有问题吧!!<br /> <br /> 下面有一张我数据库截图的图片,首先UserInfo表是用户登录,没问题!!   然后查出了SysRole表中  用户对应的角色,然后表关联到  RoleRight这个表,  根据这个角色查SysFun中对应的权限!!!</p> <p> </p> <p><span style="color: #ff0000;">当然这个UserInfo还关联了其他的很多张表,它和RoInfo表配置的关系如下:   麻烦大家帮我看看,感激不尽!!!<br /> </span> </p> <p>   <br />       <class name="OfficeWH.entity.UserInfo" table="UserInfo" schema="dbo" catalog="MyOffice"><br />         <id name="userId" type="java.lang.String"><br />             <column name="UserId" length="50"><br />             <generator class="native"><br />         </id><br />         <many-to-one name="userState" class="OfficeWH.entity.UserState" fetch="select"><br />             <column name="UserStateId" not-null="true"><br />         </many-to-one><br /> <span style="color: #ff0000;">        //这里就是和  RoleInfo对应的关系配置文件</span> <br />         <many-to-one name="roleInfo" column="RoleId" class="OfficeWH.entity.RoleInfo" fetch="select" lazy="false"><br />         </many-to-one><br />         <br />         <property name="userName" type="java.lang.String"><br />             <column name="UserName" length="50" not-null="true"><br />         </property><br />         <property name="password" type="java.lang.String"><br />             <column name="Password" length="50" not-null="true"><br />         </property><br />         <property name="departId" type="java.lang.Integer"><br />             <column name="DepartId" not-null="true"><br />         </property><br />         <property name="gender" type="java.lang.Integer"><br />             <column name="Gender" not-null="true"><br />         </property><br />         <set name="fileInfos"><br />             <key><br />                 <column name="FileOwner" length="50" not-null="true"><br />             </key><br />             <one-to-many class="OfficeWH.entity.FileInfo"><br />         </set><br />         <set name="schedules"><br />             <key><br />                 <column name="CreateUser" length="50" not-null="true"><br />             </key><br />             <one-to-many class="OfficeWH.entity.Schedule"><br />         </set><br />         <set name="readCommonMessages"><br />             <key><br />                 <column name="UserId" length="50" not-null="true"><br />             </key><br />             <one-to-many class="OfficeWH.entity.ReadCommonMessage"><br />         </set><br />         <set name="manualSigns"><br />             <key><br />                 <column name="UserId" length="50" not-null="true"><br />             </key><br />             <one-to-many class="OfficeWH.entity.ManualSign"><br />         </set><br />         <set name="myNotes"><br />             <key><br />                 <column name="CreateUser" length="50" not-null="true"><br />             </key><br />             <one-to-many class="OfficeWH.entity.MyNote"><br />         </set><br />         <set name="loginLogs"><br />             <key><br />                 <column name="UserId" length="50" not-null="true"><br />             </key><br />             <one-to-many class="OfficeWH.entity.LoginLog"><br />         </set><br />         <set name="departInfos"><br />             <key><br />                 <column name="PrincipalUser" length="50" not-null="true"><br />             </key><br />             <one-to-many class="OfficeWH.entity.DepartInfo"><br />         </set><br />         <set name="messages"><br />             <key><br />                 <column name="FromUserId" length="50" not-null="true"><br />             </key><br />             <one-to-many class="OfficeWH.entity.Message"><br />         </set><br />         <set name="operateLogs"><br />             <key><br />                 <column name="UserId" length="50" not-null="true"><br />             </key><br />             <one-to-many class="OfficeWH.entity.OperateLog"><br />         </set><br />     </class></p> <p> </p> <p style="background-color: #ffffff;"><span style="color: #ff0000;">RoleInfo表配置:</span> </p> <p> </p> <p>     <bag name="roleRights" table="RoleRight"  ="" order-by="NodeId asc"><br />             <key column="RoleId"><br />                 <!----><br />            <!----><br />             <many-to-many class="OfficeWH.entity.RoleRight" column="NodeId"><br />         </bag><br />         <bag name="userInfos" table="UserRole" inverse="true"><br />             <key column="RoleId"><br />                 <!----><br />            <!----><br />             <many-to-many class="OfficeWH.entity.UserInfo"><br />         </bag></p> <p> </p> <p><span style="color: #ff0000;">RoleRight表配置:</span> </p> <p> </p> <p>  <many-to-one name="sysFun" class="OfficeWH.entity.SysFun" fetch="select"><br />             <column name="NodeId" length="50" not-null="true"><br />         </many-to-one><br />         <many-to-one name="roleInfo" class="OfficeWH.entity.RoleInfo" fetch="select"><br />             <column name="RoleId" not-null="true"><br />         </many-to-one></p> <p> </p> <p><span style="color: #ff0000;">SysFun表配置:</span> </p> <p> </p> <p>  <set name="roleRights"><br />             <key><br />                 <column name="NodeId" length="50"><br />             </key><br />             <many-to-many class="OfficeWH.entity.RoleRight" column="RoleId"><br />         </set></p> <p> </p>
©️2020 CSDN 皮肤主题: 编程工作室 设计师:CSDN官方博客 返回首页