Hibernate的异常处理(No row with the given identifier exists)

    xiaoxiao2021-12-01  16

    Hibernate的异常处理(No row with the given identifier exists)

    异常详细: HTTP Status 500 - No row with the given identifier exists: [com.cc.erp.entity.Dep#3]配置详细: <hibernate-mapping> <class name="com.cc.erp.entity.Emp" table="emp"> <id name="uuid"> <generator class="org.hibernate.id.SequenceGenerator"> <param name="sequence">emp_seq</param> </generator> </id> <property name="username" /> <property name="pwd" /> <property name="name" /> <property name="gender" /> <property name="email" /> <property name="tele" /> <property name="address" /> <property name="birthday" /> <!--对多一关联,只在多的一方配置--> <many-to-one name="dep" class="com.cc.erp.entity.Dep" column="depuuid"></many-to-one> </class> </hibernate-mapping> <hibernate-mapping> <class name="com.cc.erp.entity.Dep" table="dep"> <id name="uuid"> <generator class="org.hibernate.id.SequenceGenerator"> <param name="sequence">dep_seq</param> </generator> </id> <property name="name" /> <property name="tele" /> </class> </hibernate-mapping> public class Emp { private Long uuid; private Dep dep; } public class Dep { private Long uuid; private String name; }

    ORACLE数据库中有EMP的DEP表,页面需要显示Emp对象的Dep.name - 异常产生原因及解决办法: EMP表的外键字段depuuid中含有DEP表主键字段uuid中没有的值,即DEP表中没有EMP表指定的记录,这是纯粹的数据问题,需要在映射文件中进行配置

    <many-to-one name="dep" class="com.cc.erp.entity.Dep" column="depuuid" not-found="ignore"></many-to-one>

    如果采用注解方式开发,则需要在指定属性上添加注解@NotFound(action=NotFoundAction.IGNORE)

    转载请注明原文地址: https://ju.6miu.com/read-679447.html

    最新回复(0)