似乎存储毫秒精度的时间戳是hibernate的一个已知问题。我在数据库中的字段最初设置为timestamp(3),但我尝试将datetime(3)设置为well...unfortunately,没有任何区别。
我尝试过使用Timestamp和Date类,最近我开始使用joda-time库。经过这么多努力,我仍然能够以毫秒级的精度保存时间戳。
我的类映射包含以下属性:
<property name="startTime" column="startTime" type="org.jadira.usertype.dateandtime.joda.PersistentDateTime" length="3" precision="3" />和I'v自定义方言类
public class MySQLQustomDialect extends MySQL5InnoDBDialect{
protected void registerColumnType(int code, String name) {
if (code == Types.TIMESTAMP) {
super.registerColumnType(code, "TIMESTAMP(3)");
} else {
super.registerColumnType(code, name);
}
}
}如果我手动将数据输入数据库,hibernate会设法检索子第二部分。
有没有办法解决这个问题?
发布于 2014-04-24 04:02:20
您是否正在MariaDB 5.5中使用MySQL连接器/ JDBC驱动程序?
Connector/J通常仅在检测到服务器足够新时才向服务器发送毫秒部分,此检测检查服务器版本是否为>= 5.6.4。这显然不适用于MariaDB 5.5.x。
你可以在这里看到Connector/J源代码的相关部分:
使用MariaDB自己的JDBC驱动程序(Connector Client)可能会有所帮助(我还没有尝试过),但是我意外地发现,将useServerPrepStmts=true添加到连接字符串中也可以使用MariaDB/J。
https://stackoverflow.com/questions/23142614
复制相似问题