Hibernate 3.6.7-final java.lang.IllegalArgumentException:时间戳格式必须为yyyy-mm-dd hh:mm:ss [.fffffffff]

时间:2014-09-01 08:30:27

标签: java oracle hibernate date timestamp

我的实体中有这个字段。

@Column(name = "CREATED_DATE")
@Temporal(TemporalType.DATE)
@DateTimeFormat(style = "yyyy-MM-dd-HH.mm.ss.SSSSSS")
private Date createdDate;

当我使用TemporalType.TIMESTAMP时,我收到以下错误:

Caused by: java.lang.IllegalArgumentException: Timestamp format must be yyyy-mm-dd hh:mm:ss[.fffffffff]
    at java.sql.Timestamp.valueOf(Unknown Source) ~[na:1.6.0_45]
    at oracle.jdbc.driver.CharCommonAccessor.getTimestamp(CharCommonAccessor.java:544) ~[ojdbc6-11.2.0.2.0.jar:11.2.0.2.0]
    at oracle.jdbc.driver.T4CCharAccessor.getTimestamp(T4CCharAccessor.java:851) ~[ojdbc6-11.2.0.2.0.jar:11.2.0.2.0]
    at oracle.jdbc.driver.OracleResultSetImpl.getTimestamp(OracleResultSetImpl.java:1408) ~[ojdbc6-11.2.0.2.0.jar:11.2.0.2.0]
    at oracle.jdbc.driver.OracleResultSet.getTimestamp(OracleResultSet.java:512) ~[ojdbc6-11.2.0.2.0.jar:11.2.0.2.0]
    at org.apache.commons.dbcp.DelegatingResultSet.getTimestamp(DelegatingResultSet.java:300) ~[commons-dbcp-1.3.jar:1.3]
    at org.apache.commons.dbcp.DelegatingResultSet.getTimestamp(DelegatingResultSet.java:300) ~[commons-dbcp-1.3.jar:1.3]
    at org.hibernate.type.descriptor.sql.TimestampTypeDescriptor$2.doExtract(TimestampTypeDescriptor.java:62) ~[hibernate-core-3.6.7.Final.jar:3.6.7.Final]
    at org.hibernate.type.descriptor.sql.BasicExtractor.extract(BasicExtractor.java:64) ~[hibernate-core-3.6.7.Final.jar:3.6.7.Final]
    at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:254) ~[hibernate-core-3.6.7.Final.jar:3.6.7.Final]
    at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:250) ~[hibernate-core-3.6.7.Final.jar:3.6.7.Final]
    at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:230) ~[hibernate-core-3.6.7.Final.jar:3.6.7.Final]
    at org.hibernate.type.AbstractStandardBasicType.hydrate(AbstractStandardBasicType.java:331) ~[hibernate-core-3.6.7.Final.jar:3.6.7.Final]
    at org.hibernate.persister.entity.AbstractEntityPersister.hydrate(AbstractEntityPersister.java:2283) ~[hibernate-core-3.6.7.Final.jar:3.6.7.Final]
    at org.hibernate.loader.Loader.loadFromResultSet(Loader.java:1527) ~[hibernate-core-3.6.7.Final.jar:3.6.7.Final]
    at org.hibernate.loader.Loader.instanceNotYetLoaded(Loader.java:1455) ~[hibernate-core-3.6.7.Final.jar:3.6.7.Final]
    at org.hibernate.loader.Loader.getRow(Loader.java:1355) ~[hibernate-core-3.6.7.Final.jar:3.6.7.Final]
    at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:611) ~[hibernate-core-3.6.7.Final.jar:3.6.7.Final]
    at org.hibernate.loader.Loader.doQuery(Loader.java:829) ~[hibernate-core-3.6.7.Final.jar:3.6.7.Final]
    at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:274) ~[hibernate-core-3.6.7.Final.jar:3.6.7.Final]
    at org.hibernate.loader.Loader.doList(Loader.java:2533) ~[hibernate-core-3.6.7.Final.jar:3.6.7.Final]
    at org.hibernate.loader.Loader.listUsingQueryCache(Loader.java:2319) ~[hibernate-core-3.6.7.Final.jar:3.6.7.Final]
    at org.hibernate.loader.Loader.list(Loader.java:2268) ~[hibernate-core-3.6.7.Final.jar:3.6.7.Final]
    at org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:119) ~[hibernate-core-3.6.7.Final.jar:3.6.7.Final]
    at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1716) ~[hibernate-core-3.6.7.Final.jar:3.6.7.Final]
    at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:347) ~[hibernate-core-3.6.7.Final.jar:3.6.7.Final]

当我使用TemporalType.DATETemporalType.TIME时,我收到此错误:

Caused by: java.lang.IllegalArgumentException: null
    at java.sql.Date.valueOf(Unknown Source) ~[na:1.6.0_45]
    at oracle.jdbc.driver.CharCommonAccessor.getDate(CharCommonAccessor.java:490) ~[ojdbc6-11.2.0.2.0.jar:11.2.0.2.0]
    at oracle.jdbc.driver.T4CCharAccessor.getDate(T4CCharAccessor.java:820) ~[ojdbc6-11.2.0.2.0.jar:11.2.0.2.0]
    at oracle.jdbc.driver.OracleResultSetImpl.getDate(OracleResultSetImpl.java:759) ~[ojdbc6-11.2.0.2.0.jar:11.2.0.2.0]
    at oracle.jdbc.driver.OracleResultSet.getDate(OracleResultSet.java:410) ~[ojdbc6-11.2.0.2.0.jar:11.2.0.2.0]
    at org.apache.commons.dbcp.DelegatingResultSet.getDate(DelegatingResultSet.java:294) ~[commons-dbcp-1.3.jar:1.3]
    at org.apache.commons.dbcp.DelegatingResultSet.getDate(DelegatingResultSet.java:294) ~[commons-dbcp-1.3.jar:1.3]
    at org.hibernate.type.descriptor.sql.DateTypeDescriptor$2.doExtract(DateTypeDescriptor.java:62) ~[hibernate-core-3.6.7.Final.jar:3.6.7.Final]
    at org.hibernate.type.descriptor.sql.BasicExtractor.extract(BasicExtractor.java:64) ~[hibernate-core-3.6.7.Final.jar:3.6.7.Final]
    at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:254) ~[hibernate-core-3.6.7.Final.jar:3.6.7.Final]
    at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:250) ~[hibernate-core-3.6.7.Final.jar:3.6.7.Final]
    at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:230) ~[hibernate-core-3.6.7.Final.jar:3.6.7.Final]
    at org.hibernate.type.AbstractStandardBasicType.hydrate(AbstractStandardBasicType.java:331) ~[hibernate-core-3.6.7.Final.jar:3.6.7.Final]
    at org.hibernate.persister.entity.AbstractEntityPersister.hydrate(AbstractEntityPersister.java:2283) ~[hibernate-core-3.6.7.Final.jar:3.6.7.Final]
    at org.hibernate.loader.Loader.loadFromResultSet(Loader.java:1527) ~[hibernate-core-3.6.7.Final.jar:3.6.7.Final]
    at org.hibernate.loader.Loader.instanceNotYetLoaded(Loader.java:1455) ~[hibernate-core-3.6.7.Final.jar:3.6.7.Final]
    at org.hibernate.loader.Loader.getRow(Loader.java:1355) ~[hibernate-core-3.6.7.Final.jar:3.6.7.Final]
    at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:611) ~[hibernate-core-3.6.7.Final.jar:3.6.7.Final]
    at org.hibernate.loader.Loader.doQuery(Loader.java:829) ~[hibernate-core-3.6.7.Final.jar:3.6.7.Final]
    at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:274) ~[hibernate-core-3.6.7.Final.jar:3.6.7.Final]
    at org.hibernate.loader.Loader.doList(Loader.java:2533) ~[hibernate-core-3.6.7.Final.jar:3.6.7.Final]
    at org.hibernate.loader.Loader.listUsingQueryCache(Loader.java:2319) ~[hibernate-core-3.6.7.Final.jar:3.6.7.Final]
    at org.hibernate.loader.Loader.list(Loader.java:2268) ~[hibernate-core-3.6.7.Final.jar:3.6.7.Final]
    at org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:119) ~[hibernate-core-3.6.7.Final.jar:3.6.7.Final]
    at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1716) ~[hibernate-core-3.6.7.Final.jar:3.6.7.Final]
    at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:347) ~[hibernate-core-3.6.7.Final.jar:3.6.7.Final]

我已尝试过@DateTimeFormat中我能想到的所有格式,但没有任何变化。

我从DB2数据库切换到Oracle(org.hibernate.dialect.Oracle10gDialect),我无法解决此错误。

1 个答案:

答案 0 :(得分:0)

问题出在与数据库映射的域对象上。

检查Domain类和所有变量声明。在域类中将其声明为Date而不是long / String的某个地方,这就是导致问题的原因。