我有以下复杂的查询,即视图,我们想消除视图并直接映射到表,我们使用Hibernate2。是否可以在Hibernate2中将多个表映射到一个类?这是我的查询。

SELECT DISTINCT
              r.id,
        rtype.name AS model_object_type_name,
        rtype.id AS model_object_type_id,
        c.id AS case_id,
        r.source_item_id AS person_id,
        c.file_number,
        c.start_date,
                a.app_start_date AS app_date,
        a.app_start_time,
        a.outcome_type AS app_outcome,
        c.primary_reference_id,
        aval.string_value AS last_mncis_refresh
FROM         my.case_file AS c INNER JOIN
             my.relation AS r ON c.id = r.target_item_id INNER JOIN
             my.item_type AS rtype ON r.item_type_id = rtype.id INNER JOIN
             my.person AS p ON p.id = r.source_item_id INNER JOIN
             my.relation AS rc ON c.id = rc.target_item_id INNER JOIN
            my.attr_value AS aval ON c.id = aval.item_id AND aval.name='test'
             INNER JOIN  my.item_type AS ptype ON p.item_type_id = ptype.id
WHERE     (ptype.name = 'Test')
AND (rtype.name = 'Test1' OR rtype.name = 'Test2' OR rtype.name = 'Test3')
AND (rc.name = 'Test4')


谢谢。

最佳答案

那是可能的。请参见description of the join element(该文档适用于休眠版本3.5。我不知道此元素是首先引入哪个版本的。请检查您的版本)。在休眠规范之前,该连接仅设计用于1:1关系,但如果仅用于读取n:1关系,则也应适用(但对于更新,插入和删除操作,可能不适用于1:1关系) )。

关于java - Hibernate将单个类映射到多个表,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/10709655/

10-14 09:59