简体   繁体   English

调用休眠查询list()方法会产生错误

[英]Calling hibernate query list() method generates errors

I'm trying to debug someone's codes. 我正在尝试调试某人的代码。 But I am not an expert of hibernate so I'm asking your help about this. 但是我不是冬眠专家,所以我想向您寻求帮助。

I am trying to retrieve a list of jobs from the database, but there seems to be a problem. 我正在尝试从数据库中检索作业列表,但是似乎存在问题。

In the entity class: 在实体类中:

//JobEntity

    @ManyToOne(cascade={CascadeType.MERGE, CascadeType.REFRESH}, fetch=FetchType.EAGER)
    @JoinColumn(name="job_id", nullable=false)
    private Job jobId;

    @Column(name="grp_id")
    private String grpId;

    @Id
    @Column(name="id", nullable=false)
    @GenericValue(strategy=GenerationType.SEQUENCE,generator="JOB_ENTITY_SEQUENCE")
    private Integer id;


//DaoImpl

    public Collection<JobEntity> getJobsByGrpId(String grpId){
        Query q = getCurrentSession().createQuery("from JobEntity je where je.grpId= :grpId order by je.id");

        q.setString("grpId", grpId);

        return q.list();
    }

And the error I get is something like this: 我得到的错误是这样的:

No row with the given identifier exists: [Job#:jb4567]... 

But in the db, the table has data. 但是在数据库中,表中有数据。

I'm not sure what's reason for this. 我不确定这是什么原因。

I tried putting a getCurrentSession.flush() statement before creating the query, and I also tried changing the cascade type of the job id from REFRESH to PERSIST, but still the same errors occur. 我尝试在创建查询之前放入getCurrentSession.flush()语句,并且还尝试将作业ID的级联类型从REFRESH更改为PERSIST,但是仍然会发生相同的错误。

Does cache have anything to do with this? 缓存与此有关吗? Or, what seems to be the problem here? 或者,这里似乎是什么问题? I'm clueless already. 我已经一无所知了。

Thanks in advance for the answers... 预先感谢您的回答...

try with the following code; 尝试以下代码;

public Collection<JobEntity> getJobsByGrpId(String grpId){
        Query q = getCurrentSession().createQuery("from JobEntity je where je.grpId= :grpId order by je.id");

q.setString("grpId", grpId);

        return q.list();
    }

you are not setting the value for the positional parameter grpId, which may be the problem. 您未设置位置参数grpId的值,这可能是问题所在。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM