Maybe the title is a little bit confusing, but I hope you read it anyway. I am working on some legacy data right now that is also used by other programs or scripts, so I am not always able to make changes to the tables. A problem that occured today: Object X can have one Object Y. Object Y doesn't need to be aware of the many X that can be related to it. Not every X has an Y, but this is not expressed by a NULL value. Instead the field is filled with zeroes. This time nothing else was dependend on those zeroes and I was able to allow null values, but that might not always be possible. So what is the best solution to handle such a case? Internally in my program I would like to handle it as a null value. On load I can set "not-found=ignore", but what should I do when saving? A possibility I thought of would be to create a dummy Y, persist X and delete the Y without cascading. I guess that no solution is really clean is such a case, but the one I thought of seems very bad. Is there a way to tell Hibernate that some special value should always be handled like NULL?
Thanks for your input!
|