QueryDSL和日期差异

时间:2015-07-19 12:32:51

标签: mysql jpa spring-data-jpa querydsl

我正在尝试使用QueryDSL计算日期差异的用户年龄。

Hibernate: select player0_.user_id as id1_31_, player0_1_.user_birthdate as user_bir2_31_, player0_1_.user_register_date as user_reg3_31_, player0_1_.user_delete_date as user_del4_31_, player0_1_.user_email as user_ema5_31_, player0_1_.user_first_name as user_fir6_31_, player0_1_.user_last_name as user_las7_31_, player0_1_.user_login as user_log8_31_, player0_1_.user_password as user_pas9_31_, player0_1_.user_status as user_st10_31_, player0_.player_description as player_d1_20_, player0_.player_height as player_h2_20_, player0_.player_picture as player_p3_20_, player0_.player_role as player_r4_20_, player0_.player_weight as player_w5_20_ from players player0_ inner join users player0_1_ on player0_.user_id=player0_1_.id where (diff_years(player0_1_.user_birthdate, current_date) between ? and ?) and (lower(player0_1_.user_first_name) like ? escape '!')
2015-07-19 14:22:16,881 [main] ERROR: org.hibernate.engine.jdbc.spi.SqlExceptionHelper - FUNCTION xxx.diff_years does not exist

但是失败了这个错误

public function action($action, $parameters = [], $absolute = true)
{
    if ($this->rootNamespace && !(strpos($action, '\\') === 0)) {
        $action = $this->rootNamespace.'\\'.$action;
    } else {
        $action = trim($action, '\\');
    }

    if (!is_null($route = $this->routes->getByAction($action))) {
        return $this->toRoute($route, $parameters, $absolute);
    }

    throw new InvalidArgumentException("Action {$action} not defined.");
}

使用MYSQL数据库或HSQL都会发生此错误。

该代码出了什么问题?

由于

1 个答案:

答案 0 :(得分:1)

遗憾的是,在Querydsl JPA

中还没有支持diff_years