Hibernate异常No row with the given identifier exists

package com.prms.urms.entity;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;

import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.NotFound;
import org.hibernate.annotations.NotFoundAction;
import org.hibernate.annotations.Parameter;

/**
 * Appfunc entity. @author MyEclipse Persistence Tools
 */
@Entity
@Table(name = "appfunc", schema = "moco_ajb")
public class Appfunc implements java.io.Serializable, Comparable<Appfunc> {

    /**
     * 请看上面多对一的地方↑↑↑
     * 注解配置解决方法:
     *使用hibernate 注解配置实体类的关联关系,在many-to-one,one-to-one关联中,一边引用自另一边的属性,如果属性值为某某的数据在数据库不存在了,hibernate默认会抛出异常。解决此问题,加上如下注解就可以了:
     *@NotFound(action=NotFoundAction.IGNORE),意思是找不到引用的外键数据时忽略,NotFound默认是exception
     */
    private static final long serialVersionUID = 1L;
    // Fields

    private String funcid;
    private String appid;
    private String funcno;
    private String funcname;
    private String sfqxrz;
    private String funcdesc;
    private Integer orderno;
    private String sfmj;
    private String funcurl;
    private String czlxbms;
    private String qzgnid;
    private String cjrid;
    private String cjr;
    private Date cjrq;
    private String zjxgrid;
    private String zhxgr;
    private Date zjxgrq;
    private String icons;

    private Appfunc appfunc;

    private Set<Appfunc> childAfs = new HashSet<Appfunc>();
    private Integer orderNum;
    private String sysjgnid;
    // Constructors

    // 是否权限认证-中文显示
    private String sfqxrzZh;
    // 是否末级功能-中文显示
    private String sfmjZh;
    // 上级功能-中文
    private String sjgnZh;
    // 上级功能ID
    private String sjgnid;
    // 所属系统中文
    private String appZh;
    // 所有子级容器
    private List<Appfunc> children = new ArrayList<Appfunc>();

    /** default constructor */
    public Appfunc() {
    }

    /** minimal constructor */
    public Appfunc(String funcid) {
        this.funcid = funcid;
    }

    /** full constructor */
    public Appfunc(String funcid, String appid, String funcno, String funcname, String sfqxrz, String funcdesc, Integer orderno, String sfmj, String funcurl, String czlxbms, String qzgnid, String cjrid, String cjr, Date cjrq, String zjxgrid, String zhxgr, Date zjxgrq) {
        this.funcid = funcid;
        this.appid = appid;
        this.funcno = funcno;
        this.funcname = funcname;
        this.sfqxrz = sfqxrz;
        this.funcdesc = funcdesc;
        this.orderno = orderno;
        this.sfmj = sfmj;
        this.funcurl = funcurl;
        this.czlxbms = czlxbms;
        this.qzgnid = qzgnid;
        this.cjrid = cjrid;
        this.cjr = cjr;
        this.cjrq = cjrq;
        this.zjxgrid = zjxgrid;
        this.zhxgr = zhxgr;
        this.zjxgrq = zjxgrq;
    }

    // Property accessors
    @Id
    @GeneratedValue(generator = "paymentableGenerator")
    @GenericGenerator(name = "paymentableGenerator", strategy = "com.prms.urms.common.IdGenerator", parameters = { @Parameter(name = "tableName", value = "func") })
    @Column(name = "FUNCID", unique = true, nullable = false, length = 20)
    public String getFuncid() {
        return this.funcid;
    }

    public void setFuncid(String funcid) {
        this.funcid = funcid;
    }

    @Column(name = "APPID", length = 20)
    public String getAppid() {
        return this.appid;
    }

    public void setAppid(String appid) {
        this.appid = appid;
    }

    @Column(name = "FUNCNO", length = 60)
    public String getFuncno() {
        return this.funcno;
    }

    public void setFuncno(String funcno) {
        this.funcno = funcno;
    }

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "REPORTCONTENT")
    @NotFound(action=NotFoundAction.IGNORE)     //在此添加一个注解就OK了。
    public Appfunc getAppfunc() {
        return appfunc;
    }

    public void setAppfunc(Appfunc appfunc) {
        this.appfunc = appfunc;
    }

    @OneToMany(cascade = CascadeType.MERGE, fetch = FetchType.EAGER, mappedBy = "appfunc")
    public Set<Appfunc> getChildAfs() {
        return childAfs;
    }

    public void setChildAfs(Set<Appfunc> childAfs) {
        this.childAfs = childAfs;
    }

    @Column(name = "FUNCNAME", length = 100)
    public String getFuncname() {
        return this.funcname;
    }

    public void setFuncname(String funcname) {
        this.funcname = funcname;
    }

    @Column(name = "SFQXRZ", length = 1)
    public String getSfqxrz() {
        return this.sfqxrz;
    }

    public void setSfqxrz(String sfqxrz) {
        this.sfqxrz = sfqxrz;
    }

    @Column(name = "FUNCDESC", length = 200)
    public String getFuncdesc() {
        return this.funcdesc;
    }

    public void setFuncdesc(String funcdesc) {
        this.funcdesc = funcdesc;
    }

    @Column(name = "ORDERNO", precision = 22, scale = 0)
    public Integer getOrderno() {
        return this.orderno;
    }

    public void setOrderno(Integer orderno) {
        this.orderno = orderno;
    }

    @Column(name = "SFMJ", length = 1)
    public String getSfmj() {
        return this.sfmj;
    }

    public void setSfmj(String sfmj) {
        this.sfmj = sfmj;
    }

    @Column(name = "FUNCURL", length = 100)
    public String getFuncurl() {
        return this.funcurl;
    }

    public void setFuncurl(String funcurl) {
        this.funcurl = funcurl;
    }

    @Column(name = "CZLXBMS", length = 2)
    public String getCzlxbms() {
        return this.czlxbms;
    }

    public void setCzlxbms(String czlxbms) {
        this.czlxbms = czlxbms;
    }

    @Column(name = "QZGNID", length = 20)
    public String getQzgnid() {
        return this.qzgnid;
    }

    public void setQzgnid(String qzgnid) {
        this.qzgnid = qzgnid;
    }

    @Column(name = "CJRID", length = 20)
    public String getCjrid() {
        return this.cjrid;
    }

    public void setCjrid(String cjrid) {
        this.cjrid = cjrid;
    }

    @Column(name = "CJR", length = 30)
    public String getCjr() {
        return this.cjr;
    }

    public void setCjr(String cjr) {
        this.cjr = cjr;
    }

    @Temporal(TemporalType.DATE)
    @Column(name = "CJRQ", length = 7)
    
    public Date getCjrq() {
        return this.cjrq;
    }

    public void setCjrq(Date cjrq) {
        this.cjrq = cjrq;
    }

    @Column(name = "ZJXGRID", length = 20)
    public String getZjxgrid() {
        return this.zjxgrid;
    }

    public void setZjxgrid(String zjxgrid) {
        this.zjxgrid = zjxgrid;
    }

    @Column(name = "ZHXGR", length = 30)
    public String getZhxgr() {
        return this.zhxgr;
    }

    public void setZhxgr(String zhxgr) {
        this.zhxgr = zhxgr;
    }

    @Temporal(TemporalType.DATE)
    @Column(name = "ZJXGRQ", length = 7)
    public Date getZjxgrq() {
        return this.zjxgrq;
    }

    public void setZjxgrq(Date zjxgrq) {
        this.zjxgrq = zjxgrq;
    }

    @Column(name = "ICONS", length = 100)
    public String getIcons() {
        return icons;
    }

    public void setIcons(String icons) {
        this.icons = icons;
    }

    @Transient
    public String getSfqxrzZh() {
        return sfqxrzZh;
    }

    public void setSfqxrzZh(String sfqxrzZh) {
        this.sfqxrzZh = sfqxrzZh;
    }

    @Transient
    public String getSfmjZh() {
        return sfmjZh;
    }

    public void setSfmjZh(String sfmjZh) {
        this.sfmjZh = sfmjZh;
    }

    @Transient
    public String getSjgnZh() {
        return sjgnZh;
    }

    public void setSjgnZh(String sjgnZh) {
        this.sjgnZh = sjgnZh;
    }

    @Transient
    public String getSjgnid() {
        return sjgnid;
    }

    public void setSjgnid(String sjgnid) {
        this.sjgnid = sjgnid;
    }

    @Transient
    public String getAppZh() {
        return appZh;
    }

    public void setAppZh(String appZh) {
        this.appZh = appZh;
    }

    @Column(name = "ORDERNUM", precision = 22, scale = 0)
    public Integer getOrderNum() {
        return orderNum;
    }

    public void setOrderNum(Integer orderNum) {
        this.orderNum = orderNum;
    }

    @Column(name = "SYSJGNID", length = 120)
    public String getSysjgnid() {
        return sysjgnid;
    }

    public void setSysjgnid(String sysjgnid) {
        this.sysjgnid = sysjgnid;
    }

    public int compareTo(Appfunc arg0) {

        return this.getOrderNum().compareTo(arg0.getOrderNum());
    }

    @Transient
    public List<Appfunc> getChildren() {
        return children;
    }

    public void setChildren(List<Appfunc> children) {
        this.children = children;
    }

}


产生此问题的原因在此记录下来:

有两张表,table1和table2. 产生此问题的原因就是table1里做了关联<one-to-one>或者<many-to-one unique="true">(特殊的多对一映射,实际就是一对一)来关联table2.当hibernate查找的时候,table2里的数据没 有与table1相匹配的,这样就会报No row with the given identifier exists这个错.(一句话,就是数据的现在hibernate配置可以基于xml配置文件和注解方式,这两种方式都能发生这个异常

以下是XML 配置形式的加法:

<many-to-one class="com.art.model.user.UserInfo" fetch="join" name="userInfo" >
   <column name="userId" unique="true"/>
</many-to-one>
<many-to-one class="com.art.model.user.UserInfo" fetch="join" name="userInfo" not-found="ignore">
   <column name="userId" unique="true"/>
</many-to-one>
时间: 2024-08-01 16:10:36

Hibernate异常No row with the given identifier exists的相关文章

Hibernate报错: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的映射

org.hibernate.ObjectNotFoundException: No row with the given identifier exists

维护老系统时出现的问题,出现的原因我简述一下: table1与table2是关联表,T1中有T2的主键 "T1_id",当T1中的 "T2_id" 不为null时,而T2中的"T2_id"为空,那么就会报上面这个错. 反之T1的"T2_id"为null,而T2中的"T2_id"不为null,没有任何影响. 所以这个错误是由于数据不匹配出现的. 解决方案: 1.在映射文件里加上 not-found="

hibernate出现No row with the given identifier exists问题

产生此问题的原因: 有两张表,table1和table2.产生此问题的原因就是table1里做了关联<one-to-one>或者<many-to-one>来关联table2.当hibernate查找的时候,table2里的数据没有与table1相匹配的,这样就会报No row with the given identifierexists这个错. 解决方法: 1.修改数据使关联字段能查询到数据 2.在<many-to-one>中设置not-found="ign

Hibernate3.x异常No row with the given identifier exists 解决方法

这个异常是在 多对一关系映射时,一方表中对应的数据不存在才抛出的.原来的配置: <many-to-one class="com.art.model.user.UserInfo" fetch="join" name="userInfo" > <column name="userId" unique="true"/> </many-to-one> 修改后的: <many

(转)收集:Hibernate中常见问题 No row with the given identifier exists问题的原因及解决

Hibernate中No row with the given identifier exists问题的原因及解决 产生此问题的原因: 有两张表,table1和table2.产生此问题的原因就是table1里做了关联<one-to-one>或者<many-to-one unique="true">(特殊的多对一映射,实际就是一对一)来关联table2.当hibernate查找的时候,table2里的数据没有与table1相匹配的,这样就会报No row with

No row with the given identifier exists

Hibernate中No row with the given identifier exists问题的原因及解决 产生此问题的原因: 有两张表,table1和table2.产生此问题的原因就是table1里做了关联<one-to-one>或者<many-to-one unique="true">(特殊的多对一映射,实际就是一对一)来关联table2.   当hibernate查找的时候,table2里的数据没有与table1相匹配的,这样就会报No row w

No row with the given identifier exists[ArtProject.Domains.Users#2]

  产生此问题的原因:              有两张表,table1和table2. 产生此问题的原因就是table1里做了关联<one-to-one>或者<many-to-one unique="true">(特殊的多对一映射,实际就是一对一)来关联table2.当hibernate查找的时候,table2里的数据没有与table1相匹配的,这样就会报No row with the given identifier exists这个错.(一句话,就是数据的

利用struts进行前端页面间传值及hibernate异常:a different object with the same identifier value was already associated with the session的总结

2017-3-16 我使用SSH框架在做单表CRUD的更新操作时遇到了一个问题,就是页面间该怎么传值?解决该需求时引发了一系列的bug,趁还记得好好总结一番. 前端页面间传值 情景:在我查出所以记录后,点击修改会链接到新的修改页面. 问题:该新页面没有之前的实体信息,该如何传递要修改的实体信息给该页面,例如id? 思路1:利用struts的action来传值. 1 <form action="deleteSerCate.action" method="post"

Hibernate 异常总结

异常一 异常一 异常描述: Sax解析异常:cvc-复杂的类型,发现了以元素maping开头的无效内容,应该是以 '{"http://www.hibernate.org/xsd/orm/cfg":property, "http://www.hibernate.org/xsd/orm/cfg":mapping, "http://www.hibernate.org/xsd/orm/cfg":class-cache, "http://www.