0

当我使用休眠执行以下代码时,出现以下错误。错误:路径表达式以复合值结尾:

代码/java方法:

MatioFunctionExpression MatioFunctionExpression = null;
MatioFunctionExpressionId MatioFunctionExpressionId = null;
try {
    MatioFunctionExpression = new MatioFunctionExpression();

    MatioFunctionExpressionId = new MatioFunctionExpressionId();
    MatioFunctionExpressionId.setMatioFunctionId(MatioFunctionId);
    MatioFunctionExpressionId.setExpressionId(expressionId);

    MatioFunctionExpression.setId(MatioFunctionExpressionId);
    List<MatioFunctionExpression> instance
        = (List<MatioFunctionExpression>) template.find("from MatioFunctionExpression MatioFunctionExpression where MatioFunctionExpression.id = ?",
                                                        MatioFunctionExpression.getId());
    logger.debug("get successful");
    if (instance.size() > 0) {
        MatioFunctionExpression = instance.get(0);
    } else {
        logger.debug("Lookup of id [" + expressionId + "] is not found in MatioFunctionExpression table");
    }
4

1 回答 1

0

由于您的实体使用复合键,我不确定是否可以编写这样的HQL查询。尝试分别添加密钥的每个参数。类似的东西:

RatioFunctionExpression ratioFunctionExpression = null;
RatioFunctionExpressionId ratioFunctionExpressionId = null;
try {
    ratioFunctionExpression = new RatioFunctionExpression();

    List<Object> params = new ArrayList<Object>();
    params.add(ratioFunctionId);
    params.add(expressionId);

    List<RatioFunctionExpression> instance
        = (List<RatioFunctionExpression>) template.find("from RatioFunctionExpression ratioFunctionExpression where ratioFunctionExpression.id.ratioFunctionId = ? and ratioFunctionExpression.id.expressionId = ?",
                                                        params.toArray());
    logger.debug("get successful");
    if (instance.size() > 0) {
        ratioFunctionExpression = instance.get(0);
    } else {
        logger.debug("Lookup of id [" + expressionId + "] is not found in RatioFunctionExpression table");
    }
于 2013-07-17T20:19:30.570 回答