休眠:自定义查询中出现意外令牌错误

时间:2018-09-27 01:18:44

标签: spring hibernate

我正在尝试对实体进行双重内部连接

BundleRepository:

@Query("select b from Bundle b inner join BundlePlan p ON b.bundle_code = p.bundle_code "
        + "inner join PlanBenefit e ON p.plan_code = e.plan_code"
        + "where b.bundle_code = ?1")
List<Bundle> findBundlePlanInfo(String bundle_code);

BundleService:

public List<Bundle> getBundlePlanInfoByBundleCode(String bundle_code);

BundleServiceImpl:

@Override
public List<Bundle> getBundlePlanInfoByBundleCode(String bundle_code) {
    return (List<Bundle>) bundleRepository.findBundlePlanInfo(bundle_code);
}

BundleController:

@RequestMapping(value="Bundle/{bundle_code}", method=RequestMethod.GET)
public ModelAndView bundleProfile(@PathVariable("bundle_code") String bundle_code) {
    ModelAndView model = new ModelAndView("bundle_profile");
    List<Bundle> bundlePlanInfo = bundleService.getBundlePlanInfoByBundleCode(bundle_code);
    model.addObject("bundlePlanInfo",bundlePlanInfo);

    return model;
}

我正在给出这样的几个错误

unexpected token: b near line 1, column 212 [select b from com.rtc_insurance.model.Bundle b inner join com.rtc_insurance.model.BundlePlan p ON b.bundle_code = p.bundle_code inner join com.rtc_insurance.model.PlanBenefit e ON p.plan_code = e.plan_codewhere b.bundle_code = ?1]

还有这个

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'bundleController': Unsatisfied dependency expressed through field 'bundleService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'bundleServiceImpl': Unsatisfied dependency expressed through field 'bundleRepository'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'bundleRepository': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Validation failed for query for method public abstract java.util.List com.rtc_insurance.repository.BundleRepository.findBundlePlanInfo(java.lang.String)!

1 个答案:

答案 0 :(得分:1)

意外令牌:b 明确提示b.bundle_code存在问题。

在where子句之前提供空格,如下所示。

@Query("select b from Bundle b inner join BundlePlan p ON b.bundle_code = p.bundle_code "
        + "inner join PlanBenefit e ON p.plan_code = e.plan_code"
        + " where b.bundle_code = ?1")