2016-08-15 87 views
0

這是我的映射。爲什麼jTDS無法將SQL Server datetime轉換爲java.sql.Timestamp?

@Column(name = "someDateTime") // which is `datetime` in SQL Server table 
public java.sql.Timestamp getSomeDateTime() { 
    return someDateTime; 
} 

URL is spring.datasource.url=jdbc:jtds:sqlserver://myUrl:1433/bizproj;socketTimeout=21600 

我使用jTDS 1.3.1和Hibernate 5.0.9以及Spring Boot 1.4與SQL Server連接。

我運行到時從SQL Server該列加載內容

Caused by: java.sql.SQLException: Value 2009-02-25 07:51:54.2730000 +00:00 cannot be converted to TIMESTAMP. 
    at net.sourceforge.jtds.jdbc.Support.convert(Support.java:516) ~[jtds-1.3.1.jar:1.3.1] 
    at net.sourceforge.jtds.jdbc.JtdsResultSet.getTimestamp(JtdsResultSet.java:1182) ~[jtds-1.3.1.jar:1.3.1] 
    at net.sourceforge.jtds.jdbc.JtdsResultSet.getTimestamp(JtdsResultSet.java:1334) ~[jtds-1.3.1.jar:1.3.1] 
    at org.hibernate.type.descriptor.sql.TimestampTypeDescriptor$2.doExtract(TimestampTypeDescriptor.java:76) ~[hibernate-core-5.0.9.Final.jar:5.0.9.Final] 
    at org.hibernate.type.descriptor.sql.BasicExtractor.extract(BasicExtractor.java:47) ~[hibernate-core-5.0.9.Final.jar:5.0.9.Final] 
    at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:238) ~[hibernate-core-5.0.9.Final.jar:5.0.9.Final] 
    at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:234) ~[hibernate-core-5.0.9.Final.jar:5.0.9.Final] 
    at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:224) ~[hibernate-core-5.0.9.Final.jar:5.0.9.Final] 
    at org.hibernate.type.AbstractStandardBasicType.hydrate(AbstractStandardBasicType.java:300) ~[hibernate-core-5.0.9.Final.jar:5.0.9.Final] 
    at org.hibernate.persister.entity.AbstractEntityPersister.hydrate(AbstractEntityPersister.java:2727) ~[hibernate-core-5.0.9.Final.jar:5.0.9.Final] 
    at org.hibernate.loader.Loader.loadFromResultSet(Loader.java:1729) ~[hibernate-core-5.0.9.Final.jar:5.0.9.Final] 
    at org.hibernate.loader.Loader.instanceNotYetLoaded(Loader.java:1655) ~[hibernate-core-5.0.9.Final.jar:5.0.9.Final] 
    at org.hibernate.loader.Loader.getRow(Loader.java:1544) ~[hibernate-core-5.0.9.Final.jar:5.0.9.Final] 
    at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:727) ~[hibernate-core-5.0.9.Final.jar:5.0.9.Final] 

的價值,排在數據庫以下錯誤是2009-02-25 07:51:54.273

我可能失去了一些東西,但我即使經過一些調查後仍無法弄清楚。我嘗試了joda時間和jadira,但異常沒有改變。任何指導非常感謝。

回答

0

值2009-02-25 07:51:54.2730000 +00:00不能轉換爲TIMESTAMP。

注意日期/時間值結束時的時區偏移+00:00。它表明SQL Server列幾乎肯定是datetimeoffset類型,而不是您在問題中陳述的datetime

有關使用JTDS datetimeoffset值的詳細信息,請參閱相關的問題:

using the datetimeoffset datatype with jTDS

相關問題