We have some columns with data that must always be in uppercase to ensure uniqueness. I was wondering if hibernate can force all such columns to uppercase via some configuration file change?
We actually use a custom UserType for encrypting/decrypting column data for some other table, but I figured that would be overkill just to uppercase everything…
Alternatively, I was thinking about modifying the models such that all getters/setters will uppercase any string coming and going.
The worst(?) case scenario is to modify the Oracle column constraint to ignore case while checking uniqueness.
Any thoughts?
I decided to implement a UserType…it is as close to a hibernate configuration as I can get…here’s the code…
Consider this property element
So the reasoning…As hibernate inserts the data, this type will convert the string to uppercase. As hibernate selects data, the same thing happens. The advantage this class has over just changing the bean’s get/set to uppercase everything is when I use a Criteria to select on serialNumber. Hibernate will also uppercase my parameter as it will cast/apply the same type as defined in the table configuration.
Therefore, I don’t need to remember to manually uppercase all of my search criteria for serial numbers…hibernate takes care of that for me…that’s exactly what I’m trying to achieve here!
I have a JUnit that demonstrates all of this stuff, but I think my answer is way too big as it is…