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.
|