Because our database has evolved over several years, our boolean columns often have different values:
Y/N
Y/<blank>
T/F
T/<blank>
Obviously, the best solution would be to have consistent data. Unfortunately, that's not possible because we'd have to check/modify thousands of lines of C code. Given we can't do that...
Instead of messing around with hibernate.query.substitutions, I'm using extending CharBooleanType when I have to(where blank == false), and using YesNoType and/or TrueFalseType when I don't.
Right now, I'm having a problem with YesNoType. It works well when I read from the database, my Boolean attributes get populated correctly, but when I try to write back to the database, it tries to insert "true" or "false", not "Y" or "N".
With debug logging and SQL logging enabled:
Code:
Hibernate: update eousr.TARIFF set LOCK_COL=?, NAME=?, SHORT_NAME=?, DIVISION_CD
=?, TEXT=?, MANUAL_FLG=?, PERCENT_62_FLG=?, ICC_CD=?, CURRENCY_CD=?, BILL_MILES_
OVERRIDE_FLG=?, DISCOUNT_PCT=?, ZIP_BASED_FLG=?, EFFECTIVE_DT=?, EXPIRE_DT=?, MO
D_USER=?, MOD_DT=?, ZONE_PANE_ID=? where TARIFF_ID=? and LOCK_COL=?
10:22:40,921 DEBUG LongType:44 - binding '2' to parameter: 1
10:22:40,921 DEBUG StringType:44 - binding 'INTRA CANADIAN TARIFF' to parameter: 2
10:22:40,921 DEBUG StringType:44 - binding '402ALK800' to parameter: 3
10:22:40,921 DEBUG StringType:44 - binding '1$' to parameter: 4
10:22:40,931 DEBUG StringType:44 - binding 'WITHIN CANADA (INTER AND INTRA) USING PCMILER 2000.' to parameter: 5
10:22:40,931 DEBUG StringType:44 - binding 'Y' to parameter: 6
10:22:40,931 DEBUG YesNoType:44 - binding 'false' to parameter: 7
10:22:40,931 DEBUG StringType:44 - binding 'FDCC' to parameter: 8
10:22:40,941 DEBUG StringType:44 - binding 'CDN' to parameter: 9
10:22:40,941 DEBUG YesNoType:44 - binding 'false' to parameter: 10
10:22:40,941 DEBUG IntegerType:44 - binding '0' to parameter: 11
10:22:40,941 DEBUG YesNoType:44 - binding 'true' to parameter: 12
10:22:40,941 DEBUG TimestampType:44 - binding '12 September 2003 10:22:40' to parameter: 13
10:22:40,941 DEBUG TimestampType:44 - binding '31 December 2099 11:59:59' to parameter: 14
10:22:40,941 DEBUG TimestampType:44 - binding '12 September 2003 10:22:40' to parameter: 15
10:22:40,951 DEBUG StringType:44 - binding 'hib' to parameter: 16
10:22:40,951 DEBUG LongType:44 - binding '0' to parameter: 17
10:22:40,951 DEBUG LongType:44 - binding '2150' to parameter: 18
10:22:40,951 DEBUG LongType:44 - binding '1' to parameter: 19
10:22:40,961 WARN JDBCExceptionReporter:38 - SQL Error: 1401, SQLState: 23000
10:22:40,961 ERROR JDBCExceptionReporter:46 - ORA-01401: inserted value too large for column
You can see that parameter #7(PERCENT_62_FLG), parameter #10(OVERRIDE_FLG) and parameter #12(ZIP_BASED_FLG) are getting bound to "true" or "false" and not "Y" or "N"
Ignore parameter #6(MANUAL_FLG), that's morphed away from boolean data to having 3 possible values.
Is this the expected behavior? Am I using these types incorrectly?
Thanks.
Eric