Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
Originally posted by David Harkness:
Doesn't the CANDIDATE table have two columns that make up the FK to CMLOOKUPS: LOOKUP and TABLENAME (or some other names)? Or do you have an alternate, single-column key in CMLOOKUPS that you use for joining to CANDIDATE? I don't even know if Hibernate supports that, but I know you could model it that way in SQL. Of course, I'd flip the AK and PK around in that case, but I don't know your setup.
Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
Originally posted by David Harkness:
Hmm, so if I understand correctly, the primary key of the CMLOOKUPS table is (LOOKUP, TABLENAME), and the foreign key to it in the CANDIDATE table is (APPOINTEDROLE). Oh I see, logically CANDIDATES only ever point to CMLOOKUPS whose TABLENAME is "AppointedRole", so you've omitted the TABLENAME half of the PK from the FK. Is this correct?
Yes, that's exactly what it means. The whole database consists of some 50 tables with not a single foreign key constraint! (it's the schema of a certain very f*ed up product)Originally posted by David Harkness:
But doesn't this mean that your database doesn't actually have an FK constraint?
I know. I've also been pretty much on the greenfield side when it comes to database schemas. This particular project has been a rather nightmare'ish experience in that you can find practically any classic s/w engineering/design screw-up around any corner you decide to turn...Originally posted by David Harkness:
I've always had the luxury of designing the database model and using single-column surrogate keys. ... The more I read forum posts, the more I realize how truly lucky I have been!
Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
Looking at the DTD for the <many-to-one> and <column> elements, I'm guessing the former. However, if you're feeling particularly brave and generous you could try wrangling it in there. My guess is that you'd need to add a "value='...'" attribute to the <column> element. How to have Hibernate then use that attribute ... well, probably not as simple as altering the DTD.Originally posted by Lasse Koskela:
it seems like either Hibernate doesn't support this kind of "smart" composite-id association or they just decided not to tell anyone how to configure such a beast
Originally posted by David Harkness:
I bet that is a huge relief.
Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
Originally posted by David Harkness:
So do I understand you correctly that this solves your issue without having to add the column?
Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
I think that should be plastered on every page of hibernate.org.Originally posted by Lasse Koskela:
Although the best alternative would've been to not have the composite-id's in the first place...
Don't get me started about those stupid light bulbs. |