Link to home
Start Free TrialLog in
Avatar of BrianMc1958
BrianMc1958

asked on

Can Hibernate persist a string as a number?

Dear Experts,

My app processes data from multiple vendors whose formats vary slightly.  99% of the fields are of the same type, but a few vary.  For instance, transaction codes are alpha in some, and numeric in others.  For business reasons, it was decided that our actual databases at customer sites would reflect these differences.

I currently have a home-grown data layer that takes that into account.  This allows my application to treat all such "morphable" fields as Strings internally.  Therefore, I have a single code base that works against a variety of slightly different databases.  When my application asks my data layer to persist a transaction code, for example, it first queries the metadata of the local database, and then persists it either as a string or as an integer.  It reverses the process when I retrieve it.

I'm telling you all this because I'm considering switching to Hibernate.  (Like you folks told me to several years ago.)  I don't know much about Hibernate yet, but that would be the key question.

Can my app tell Hibernate: Take this String, and persist it to some local db field, and if that db field is an integer, first convert the String to an integer?

If so, can you give me an idea of how to go about it, and how much trouble it would be? ( We only have about six such fields we really care about.)

Thanks!
BrianMc1958
ASKER CERTIFIED SOLUTION
Avatar of Dejan Pažin
Dejan Pažin
Flag of Austria image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of BrianMc1958
BrianMc1958

ASKER

I'm readng the first link.  Could I ask if this is right?

In addition to standard mappings, Hibernate will let me write my own classes that will encapsulate custom mappings.  Within that class, I can put any logic I want, such as "If the underlying database field is a number, convert it to a String.  Otherwise, just pass String as is."

Is that right?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks very much.