hql 函数 current_timestamp() 是使用运行 java 代码的服务器还是运行数据库的服务器的时间?
问问题
5255 次
2 回答
5
HQL查询被翻译成SQL查询,SQL查询由数据库执行。因此current_timestamp()
等效的 SQL 函数将在您的数据库服务器上执行。
于 2013-10-08T18:26:04.130 回答
0
在hibernate中,对于每个数据库,都有Dialect
类。这些是特定数据库的适配器。类似的功能current_timestamp
在这些类中定义。例如,MySQL 5.7 Dialect 是:
public class MySQL57Dialect extends MySQL55Dialect {
public MySQL57Dialect() {
super();
registerColumnType( Types.TIMESTAMP, "datetime(6)" );
registerColumnType( Types.JAVA_OBJECT, "json" );
final SQLFunction currentTimestampFunction = new StaticPrecisionFspTimestampFunction("now", 6 );
registerFunction( "now", currentTimestampFunction );
registerFunction( "current_timestamp", currentTimestampFunction );
registerFunction( "localtime", currentTimestampFunction );
registerFunction( "localtimestamp", currentTimestampFunction );
registerFunction( "sysdate", new StaticPrecisionFspTimestampFunction( "sysdate", 6 ) );
}
public boolean supportsRowValueConstructorSyntaxInInList() {
return true;
}
}
如您所见,那里有功能注册。 完整代码在 GitHub 页面中处于休眠状态。
于 2019-06-06T10:18:54.523 回答