本文介绍了将ORACLE TIMESTAMP(9)字段映射到java.util.Date的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Java中将ORACLE TIMESTAMP(9)字段映射到java.sql.Timestamp或java.util.Date时出现问题版本:-ojdbc 11.2.0.1.0休眠注释3.3.1.GAejb3-persistence 1.0.1.GA

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

尝试映射

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

获取例外

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

进一步调查后,我发现代码在Table.java的以下行中返回"false"

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 );
    Date或Timestamp字段的
  1. col.getSqlType(方言,映射)是日期.columnInfo.getTypeName()是时间戳记,因此if查询的第一部分将不匹配

  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

col.getSqlTypeCode(mapping)返回93(这是Types.TIMESTAMP的代码).但是,columnInfo.getTypeCode()返回1111.因此,即使查询的第二部分也不匹配.

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.

问题是,在为字段UPDATE_TIMESTAMP_9填充ColumnMetadata rs.getInt("DATA_TYPE")时,返回的1111是Types.OTHER的代码.请注意,如果我在oracle columnInfo.getTypeCode()中使用TIMESTAMP(6)字段,则正确返回93,并且代码成功插入了一条记录.问题仅在于TIMESTAMP(9).

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).

在休眠论坛上此处交叉发布

推荐答案

我禁用了模式验证,并且工作正常.

I disabled schema validation and it worked ok.

这篇关于将ORACLE TIMESTAMP(9)字段映射到java.util.Date的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-27 22:53