The fact I am considering this probably means my object model sucks, but hey.
My idea was to have declarations in the database and hibernate enforce integrity for me. I'm not sure sure that's 100% possible.
Here's the problem.
I have a User object that has multiple UserData objects associated with it (each one has userdata specific to a given language). There originally was a Set of Userdata inside of User
So for Hibernate, I implemented a LanguageCode object and declared UserData Many-to-One to both the User and LanguageCode objects.
At the time I wondered if this was the right way to go. I mean LanguageCode basically only contains a String. The only reason I created it at all was for declaring the Many-to-one relationship that existed, thinking Hibernate would help enforce it.
Simple so far, right?
Eventually I came to the conclusion that in order to easily get to a specific language's UserData Object, I should make UserData a Map element of User. Again no problem.
But Referencing the Map with a LanguageCode Object is cumbersome. I should be able to reference it with the approriate String. (Be aware that I have other tables where this problem would appear. This is just one such example)
My options appear to be:
1) Punt the LanguageCode many-to-one entirely and just make it a string instead, relying on a FK in the database to enforce it for me
2) Keep it, and create a string field in the class too which I can reference for purposes of the map. I keep my many-to-one, but if I do this "denormalization" though, what did I gain??? I mean, why bother?
Suggestions?
_________________ "A statistician is a mathmetician, broken down by age and sex".
|