2012-05-22 121 views
0

我有以下複雜的查詢,它是視圖,我們想消除視圖並直接映射到表,我們使用Hibernate2。是否有可能將多個表映射到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') 

謝謝。

回答

1

這是可能的。請參閱description of the join element(該文檔適用於休眠版本3.5,我不知道該元素是首先引入的版本,請檢查您的版本)。至於hibernate規範,連接只設計爲1:1關係,但是如果僅用於讀取n:1關係,也應該工作(但是對於更新,插入和刪除,可能不適用於:1關係)。