简体   繁体   English

具有datetime2的H2 DB

[英]H2 DB with datetime2

I'm trying to set up an embedded database H2 in an project that I took over. 我试图在我接管的项目中建立嵌入式数据库H2。 Now we have an sql server with a column value type datetime2 . 现在,我们有了一个列值类型为datetime2的sql服务器。

H2 can't create the column with type datetime2 , if I change it to normal datetime then all goes correct but of course the project itself gives problems cause hibernate annotation is wrong because the DB column is a datetime2 . H2无法创建类型为datetime2的列,如果我将其更改为正常的datetime则一切正常,但是项目本身会出现问题,原因是冬眠注释错误,因为DB列是datetime2

the code : 编码 :

@Column(name = "LASTUPDATETIME", columnDefinition = "datetime2 DEFAULT CURRENT_TIMESTAMP")
private Timestamp timeStamp;

Can this be done with H2(changing annotation for testing or let H2 accept datetime2) or do I have to search for another embedded database? 可以使用H2(更改测试注释或让H2接受datetime2)完成此操作,还是必须搜索另一个嵌入式数据库?

The H2 database does not currently support the data type datetime2 (as of version 1.3.176). H2数据库当前不支持数据类型datetime2 (从1.3.176版本开始)。 However, support for it was added to the trunk now and will be available in the next release. 但是,现在已将对它的支持添加到了主干中,并且将在下一版本中提供。

So, if you want to use H2 now, then you would either use a newer version (you could build it yourself for example), or change to datetime until you are using a newer version. 因此,如果要立即使用H2,则可以使用较新的版本(例如,可以自己构建),也可以更改为datetime直到使用较新的版本。

The Java Date column type should work for you, datetime2 is a Microsoft specific data type. Java Date列类型应该适合您,datetime2是Microsoft特定的数据类型。 I've seamlessly migrated applications from MS SQL Server to H2 database before, I had to change the annotation of course, but calculations etc. were not affected. 之前,我已经将应用程序从MS SQL Server无缝迁移到H2数据库,我当然不得不更改注释,但是计算等没有受到影响。

Possibly tangential. 可能相切。 DATETIME2 is supported in H2, but DATETIME2(7) (or any other precision value) is no longer working as-of H2 4.197. H2支持DATETIME2 ,但H2 4.197以后不再使用DATETIME2(7) (或任何其他精度值)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM