Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

shared id for 2 tables.

 
lynn fann
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
lynn fann
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 115
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,

ok, thanks for your suggestion. thanks.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic