I believe the following situation is a good candidate for using a Custom Type (org.hibernate.UserType) or a Hibnerate Interceptor, but I'm not sure and I'm not sure which is most appropriate...
I'm working on converting a legacy software system to a Java web application. The legacy software pads several text fields with trailing space characters for the length of the field. Even worse, there is a foreign key field (trans_id) that a VARCHAR of 9 and the legacy software puts 9 space characters in it instead of making it NULL when there is no related foreign key value/record.
So, I'd like to be able to map this in Hibernate, but to tell Hibernate to treat a tran_id value of all spaces as NULL (i.e. don't try to load the associated record). There are other fields, such as the user_id that is used for logging in, that I'd just like to trim().
I believe that I could use a Custom Type for trimming the fields, but I'm not sure if that will work for the trans_id foreign key field that I want to set to NULL if it is all spaces. I would like to map it as a one-to-many relationship in the mapping file so that the related WorkflowTransaction record for a given trans_id will be loaded along with the primary record (Alert table). My Alert object has to have a trans_id right now instead of a WorkflowTransaction object as an attribute since Hibernate chokes on the space characters because there is no WorkflowTransaction record in the database with a key value of 9 space characters.
|