-->
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.  [ 8 posts ] 
Author Message
 Post subject: Using YesNoType
PostPosted: Fri Sep 12, 2003 11:18 am 
Beginner
Beginner

Joined: Tue Aug 26, 2003 1:02 pm
Posts: 34
Location: Akron, OH
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


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 12, 2003 11:41 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Hibernate logs the actual property value that is being bound, not what the Type translates it to.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 12, 2003 11:49 am 
Beginner
Beginner

Joined: Tue Aug 26, 2003 1:02 pm
Posts: 34
Location: Akron, OH
The boolean stuff is the only thing I can think of that is wrong.
I retrieving a TariffStateObject, tariffState.setManual("O"), then call session.update. And somewhere in the mix I'm getting the "java.sql.SQLException: ORA-01401: inserted value too large for column" Exception.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 12, 2003 11:53 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Well, I invite you to inspect the source of CharBooleanType. Thats why its open source!


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 12, 2003 1:08 pm 
Beginner
Beginner

Joined: Tue Aug 26, 2003 1:02 pm
Posts: 34
Location: Akron, OH
OK, I've verified that YesNoType is actually putting "Y" and "N" back in the prepared statement. The only thing I can think of it being now is my date columns, everything other column are simple strings which haven't even changed since the read. Since Oracle doesn't say which column is too big, this is quit hard to figure out.
I have dates mapped like this:
Code:
<property
  name="effectiveDate"
  type="java.sql.Timestamp"
  column="EFFECTIVE_DT"
  not-null="true"
  length="7">

Attribute/getter/setter:
Code:
private java.sql.Timestamp effectiveDate;
public java.sql.Timestamp getEffectiveDate() {
    return effectiveDate;
}
public void setEffectiveDate(final java.sql.Timestamp effectiveDate) {
    this.effectiveDate = effectiveDate;
}


Table definition (partial) (Oracle8)
Code:
SQL> desc eousr.tariff
Name                                      Null?    Type
----------------------------------------- -------- ----------------------------
EFFECTIVE_DT                              NOT NULL DATE


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 12, 2003 1:19 pm 
Beginner
Beginner

Joined: Tue Aug 26, 2003 1:02 pm
Posts: 34
Location: Akron, OH
Ok, I've verified the problem is with my date columns. If I remove my date columns from the mapping, it works just fine. Is there something fundamentally wrong with how I've setup my mapping for dates?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 12, 2003 1:25 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Looks fine to me.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 12, 2003 2:58 pm 
Beginner
Beginner

Joined: Tue Aug 26, 2003 1:02 pm
Posts: 34
Location: Akron, OH
I put back in the mappings and specified update="false" and they read fine and now the other columns are persisted just fine. I can't imagine timestamps are broken, so any ideas on what to look at next?


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

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:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.