-->
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.  [ 4 posts ] 
Author Message
 Post subject: Complex primary keys
PostPosted: Wed Feb 02, 2005 7:08 am 
Newbie

Joined: Mon Jan 31, 2005 2:50 pm
Posts: 5
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


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 02, 2005 7:37 am 
Newbie

Joined: Mon Jan 31, 2005 2:50 pm
Posts: 5
I just read about a collection-key-column property. Should this be used?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 02, 2005 8:21 am 
Newbie

Joined: Wed Sep 01, 2004 9:04 am
Posts: 18
Location: Enschede, Netherlands
I think you are looking for a composite-id mapping option.

Check the Hibernate reference documentation:
http://www.hibernate.org/hib_docs/reference/en/html/mapping.html#mapping-declaration-compositeid


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 02, 2005 8:30 am 
Newbie

Joined: Mon Jan 31, 2005 2:50 pm
Posts: 5
thanks a lot!


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

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.