为什么这个简单的hql查询不起作用?未分类的SQLException

时间:2014-04-28 13:25:22

标签: hibernate postgresql hql

我有两个表:Research和userResearch,Research使用@OneToMany将userResearches列表映射到userResearch。我试图执行一个简单的hql查询

from Research r inner join r.userResearches ur where ur.user=:user

并获得此例外:

Hibernate operation: could not execute query; uncategorized SQLException for SQL [select...]; SQL state [24000]; error code [0]; Operation requires a scrollable ResultSet, but this ResultSet is FORWARD_ONLY.; nested exception is org.postgresql.util.PSQLException: Operation requires a scrollable ResultSet, but this ResultSet is FORWARD_ONLY.

可能是什么原因? 实体映射正确,一切正常,我可以使用条件API检索两个实体。

@Entity
public class UserResearch extends ManagedEntity {

    @ManyToOne
    @JoinColumn(name = "research_id")
    private Research research;

@Entity
public class Research extends ManagedEntity {

    @OneToMany(mappedBy = "research")
    private Set<UserResearch> userResearches = new HashSet<UserResearch>(0);

1 个答案:

答案 0 :(得分:1)

我不知道具体原因,但是我使用getSession()。createQuery()重写了一个查询,并且它开始工作,在我使用GenericDao之前它使用了getHibernateTemplate。