Hibernate OneToMany关系内连接

时间:2013-03-19 14:48:05

标签: java hibernate join one-to-many

我试图在OneToMany关系中根据子类的ID属性简单地过滤掉结果,但是Hibernate(4.1.9.Final)正在生成一个Left Outer Join而不是一个内连接,从而返回结果我不想要。

型号:

父:

@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;
...
    }

DAO:

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使用内连接?

1 个答案:

答案 0 :(得分:0)

您可以尝试以下内容:

select c from Category c inner join c.testCases tc