Hello, guys.
I have the problem with char type in the database. Here is the description of my problem.
I have business object let’s name it Doc. The business object is represented table like this
CREATE TABLE DocObject(
ID [int] IDENTITY(1,1) NOT NULL,
Name [varchar] (80) NOT NULL,
Prefix [char] (5) NOT NULL
)
The most interesting filed is Prefix. The field stores prefix of documents. The length of prefix can be 0 < Prefix.Length <= 5. The DB team is decided to use char type here and I do not argue with them. So, if I insert 'AB' value into DocObject table the result will be 'AB___' (with 3 spaces in the end).
I use default access for this field in the Doc.hbm.xml, i.e. property accessor is used. It means that when the Doc object is loaded the _prefix field of Doc class will be contain spaces.
Imagine that we have web-page which uses Doc business object. The page has "Save" button for saving Doc business object. On the web-page end user can edit Doc object and store the result of editing. Of course, if end user opens the web-page does not change anything and then clicks "Save" button it means that update of Doc object should not occur.
Also imagine that Prefix database value is 'AB___' (with 3 spaces in the end).
On other hand UI team truncs unnecessary spaces and end user sees ‘AB’ (without spaces). So if end user open web-page witch uses Doc business object and then click "Save" button the update of Doc business object will be occur because when end user clicks "Save" button it means that UI team sets _prefix field like 'AB' (without spaces) and this is different that 'AB___' (with spaces). And this is the problem.
Now in the Doc.hbm.xml I use field access for the Prefix field and add necessary spaces in the setter. But I know that this is particular case of solving the issue. Imagine that we have hundreds tables with 3-5 fields like Prefix. I am searching the general solution for such cases. Would you help me?
Thank you
_________________ http://antipod.russia.webmatrixhosting.net/
|