File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Object Relational Mapping and the fly likes shared id for 2 tables. Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Object Relational Mapping
Reply Bookmark "shared id for 2 tables." Watch "shared id for 2 tables." New topic
Author

shared id for 2 tables.

lynn fann
Ranch Hand

Joined: Oct 15, 2006
Posts: 115
i have table A and table B. for each table there will be a 'id' column as the PK. I want the ids to be shared accross these 2 table. Thats mean, if table A has an id 4, table B should not have it.

How do i achieve that using hibernate?

Do i need any special mapping?
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Ok, can I ask why? If the entities you are mapping are distinct entities, why should it matter that their primary keys use the same values?


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
lynn fann
Ranch Hand

Joined: Oct 15, 2006
Posts: 115
my table are, tbl_case, tbl_research, tbl_attachment.(for cause there are more tables) the tbl_attachment is for attachment attached to either the tbl_case, tbl_research. the tbl_attachment is using doc_id as to identify which attachment is to which.

i dont want to change the database structure.
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Not sure I completely understand your model. Is doc_id the primary key of tbl_case and tbl_research? Do is it a conditional foreign key in tbl_attachement? If it is, what you've got isn't really relational data (since it can't be described by the normal rules of a relational database) it requires business logic. So Hibernate can't help with the structure as is, it sounds like you'll have you manage your consitional key in your DAO class.

One posibility is to use a table for class hierarchy pattern in tbl_attachement. You can add a column to disciminate the type of tbl_attachement object you are persisting. That would give you a way round this model.
lynn fann
Ranch Hand

Joined: Oct 15, 2006
Posts: 115
hi,

ok, thanks for your suggestion. thanks.
 
 
subject: shared id for 2 tables.
 
Threads others viewed
1-M relationship & join queries?
Mysql query
Problem in generating the Primary Key using a Sequence
Tricky Update Statement
Calling OnClick event dynamically
developer file tools