-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Char types in the database and general solution
PostPosted: Sat Jun 24, 2006 5:27 am 
Newbie

Joined: Thu Jun 15, 2006 7:47 am
Posts: 3
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/


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.