HQL SELECT 子句不起作用

HQL SELECT clause not working

我有一个名为 CategorySet 的实体。

@Entity
@Table(name = "CATEGORY_SET")
public class CategorySet {
    @Id
    @Column(name = "ID")
    @GeneratedValue
    private Integer id;
@OneToOne
@JoinColumn(name = "ID")
private Category parent;

@OneToOne
@JoinColumn(name = "ID")
private Category child;

public CategorySet(Category parent, Category child) {
    this.parent = parent;
    this.child = child;
}

public CategorySet() {
}
}

在我的 DaoImpl 中,我只从实体中获取子列。 但它返回空列表。

String innerQueryString = "select CS.child FROM CategorySet CS";
Query innerQuery = sessionFactory.getCurrentSession().createQuery(innerQueryString);
List list = innerQuery.list();

我也用过标准。它抛出 ArrayIndexOutOfBoundException

    Criteria  criteria  =sessionFactory.getCurrentSession().createCriteria(CategorySet.class);
    criteria.setProjection(Projections.property("child")); //Projections.property is used to retrieve specific columns

    List students = criteria.list();

有人可以帮我解决这个问题吗?

通过 parent 加入列并 child 修复了它。

@Entity
@Table(name = "CATEGORY_SET")
public class CategorySet {
    @Id
    @Column(name = "ID")
    @GeneratedValue
    private Integer id;

    @OneToOne
    @JoinColumn(name = "PARENT")
    private Category parent;

    @OneToOne
    @JoinColumn(name = "CHILD")
    private Category child;

    public CategorySet(Category parent, Category child) {
        this.parent = parent;
        this.child = child;
    }

    public CategorySet() {
    }
}