sreenaji
sreenaji

Reputation: 3

Hibernate2 Mapping Single class to multiple Tables

I have following complex query which is view and we would like to eliminate the views and map directly to the tables and we use Hibernate2. Is it possible to map multiple tables to one class in Hibernate2? Here is my query.

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')

Thanks.

Upvotes: 0

Views: 273

Answers (1)

Johanna
Johanna

Reputation: 5293

That is possible. See the description of the join element (the documentation is for hibernate version 3.5. I have no idea with which version this element was introduced first. Please check with your version). Up to the hibernate specification the join is designed only for 1:1 relations, but if it is only for reading an n:1 relation also should work (but for update, insert and delete that probably won't work with a n:1 relation).

Upvotes: 1

Related Questions