-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Implementing arbitrary join condition
PostPosted: Tue Sep 29, 2009 10:59 am 
Newbie

Joined: Sun Sep 20, 2009 3:38 pm
Posts: 5
I am new to Hibernate and was wondering what would be the best way to define association between these tables in the hibernate mapping file.

create table meta_data (
metadata_id identity not null primary key,
meta_name varchar(25) not null,
meta_code varchar(10) not null,
description varchar(255) not null,
parent_meta_name varchar(25),
parent_meta_code varchar(10));

The meta_name, meta_code, parent_meta_name, and parent_meta_code uniquely identify a row within meta_data table.

create table incident (
incident_id identity not null primary key,
description varchar(150) not null,
incident_type varchar(1) not null,
incident_cause varchar(2) not null);

The tables do not have a foreign key relationship. Here is the query I would like to implement in HQL.

select i.*, mt.description, mc.description
from incident i, meta_data mt, meta_data mc
where mt.meta_name = 'incident_type'
and mt.meta_code = i.incident_type
and mc.meta_name = 'incident_cause'
and mc.meta_code = i.incident_cause

Beside the 'incident' table, there are several other tables with fields that are associated with the meta_data table. From what I understand, Hibernate supports arbitrary join condition using a formula and property-ref. However, in my case it does not work since parent name and code columns in meta data table can be null.

Redesigning the existing database schema is not an option.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.