Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can Hibernate automatically uppercase a column on read/insert via configuration?

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?

like image 381
Tim Reddy Avatar asked Mar 08 '10 19:03

Tim Reddy


1 Answers

Much cleaner approach:

@Column(name = "DUMMY")
@ColumnTransformer(read = "UPPER(DUMMY)")
private String dummy
like image 181
StasKolodyuk Avatar answered Oct 08 '22 14:10

StasKolodyuk