0

我试图根据 OneToMany 关系中子类的 ID 属性简单地过滤掉结果,但是 Hibernate (4.1.9.Final) 正在生成左外连接而不是内连接,因此返回的结果我没有'不想要。

模型:

家长:

@Entity
@Table(name = "CATEGORY")
public class Category
{
    @Id
    @Column(name = "CATEGORYID")
    private int ID;

    @Column(name = "CATEGORYNAME")
    private String name;

    @OneToMany(fetch = FetchType.EAGER)
    @JoinColumn(name = "CATEGORYID")
    @Filter(name = "TEST_RUN_ID_FILTER")
    private Collection<TestCase> testCases
...
}

孩子:

@Entity
@Table(name = "TESTCASE_NEW")
@FilterDef(name = "TEST_RUN_ID_FILTER", defaultCondition = "TESTRUNID in (:IDS)", parameters = { @ParamDef(name = "IDS", type = "int") })
public class TestCase
{
    @Id
    @Column(name = "TESTCASEID")
    private int ID;

    @Column(name = "TESTCASENAME")
    private String name;

    @Column(name = "STATUS")
    private String status;

    @Column(name = "TESTRUNID")
    private int testRunId;
...
    }

道:

public List<Category> getAllCategoriesForTestRuns(List<Integer> testRunIDs)
    {
        Session session = getSession();
        session.enableFilter("TEST_RUN_ID_FILTER")
                .setParameterList("IDS", testRunIDs);
        Query query = session.createQuery("FROM " + Category.class.getSimpleName());
        List<Category> result = query.list();
        return resul2t;
    }

如何告诉 Hibernate 使用内部联接?

4

1 回答 1

0

您可以尝试以下方法:

select c from Category c inner join c.testCases tc
于 2013-03-19T14:56:50.267 回答