1

Having issues mapping a ORACLE TIMESTAMP(9) field to java.sql.Timestamp or java.util.Date in Java Versions:- ojdbc 11.2.0.1.0 hibernate-annotations 3.3.1.GA ejb3-persistence 1.0.1.GA

Trying to map

UPDATE_TIMESTAMP_9 TIMESTAMP(9) NULL
TO
@Column(name = "UPDATE_TIMESTAMP_9")
private Date updateTimestamp_9;

Get Exception

org.hibernate.HibernateException: Wrong column type in EMPLOYEE.EMPLOYEE for column UPDATE_TIMESTAMP_9. Found: timestamp, expected: date

On investigating further i found that the code returns 'false' at the following line in Table.java

final boolean typesMatch = col.getSqlType( dialect, mapping ).toLowerCase()
                  .startsWith( columnInfo.getTypeName().toLowerCase() )
                  || columnInfo.getTypeCode() == col.getSqlTypeCode( mapping );
  1. col.getSqlType( dialect, mapping ) for Date or Timestamp field is date. columnInfo.getTypeName() is timestamp so the first part of the if query will not match

  2. col.getSqlTypeCode( mapping ) returns 93 (which is code for Types.TIMESTAMP). However, columnInfo.getTypeCode() returns 1111. So even the secondpart of the query doesnt match.

Problem is that while populating ColumnMetadata rs.getInt("DATA_TYPE") for field UPDATE_TIMESTAMP_9 returns a 1111 which is code for Types.OTHER. Please note that if i use TIMESTAMP(6) field in oracle columnInfo.getTypeCode() correctly returns 93 and the code successfully inserts a record. Problem is only with TIMESTAMP(9).

Cross posted here on hibernate forums

noi.m
  • 3,070
  • 5
  • 34
  • 57
  • It worked when i disabled hbm2ddl.auto. Any idea why it was failing while validating? Shouldn't columnInfo.getTypeCode() for TIMESTAMP(9) also return code corresponding to Types.TIMESTAMP. – noi.m Jul 18 '12 at 01:42
  • columnInfo.getTypeCode comes from the metadata reported by your JDBC driver. – Steve Ebersole Jul 18 '12 at 04:44
  • yes. not sure if this is issue with all ojdbc versions. Anyway ojdbc 11.2.0.1.0 is not too far away from the latest one (which is ojdbc 11.2.0.3). – noi.m Jul 18 '12 at 06:13

2 Answers2

0

Try to use @Temporal annotation. That might explain hibernate what to do

WeMakeSoftware
  • 9,039
  • 5
  • 34
  • 52
0

I disabled schema validation and it worked ok.

Disable schema validation? – Steve Ebersole

noi.m
  • 3,070
  • 5
  • 34
  • 57