Hi,
I have a legacy database and I'd like to start using Hibernate on the application for that database.
I have a couple of tables, Doc and DocLin, that have complex primary keys as follows (database is postgres):
mpbiz=# \d doc;
Table "public.doc"
Column | Type | Modifiers
--------------------+-----------------------------+-----------------------
tipo_ent_id | integer | not null
tipo_doc_id | integer | not null
doc_id | integer | not null
ent_id | integer | not null
cod_ext_doc | character(20) | not null
Indexes:
"doc_pkey" primary key, btree (tipo_ent_id, tipo_doc_id, doc_id)
mpbiz=# \d doc_lin;
Table "public.doc_lin"
Column | Type | Modifiers
--------------------+-----------------------------+-----------
tipo_ent_id | integer | not null
tipo_doc_id | integer | not null
doc_id | integer | not null
doc_lin_id | integer | not null
Indexes:
"doc_lin_pkey" primary key, btree (tipo_ent_id, tipo_doc_id, doc_id, doc_lin_id)
As you'll notice, there are common columns that form the primary keys (tipo_ent_id, tipo_doc_id and doc_id). What I'd like to know is if it's possible to map this for hibernate usage and if so, how can it be done.
I was thinking of creating a class (let's call it DocPK) which has the doc's primary key but I don't know how to map that to a Set so that it's values are inserted in the database.
Suggestions are deeply appreciated.
Cheers,
Celso
|