gpt4 book ai didi

java - Hibernate Exception 将 ON/WITH 条件应用于 LEFT JOIN

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:18:18 26 4
gpt4 key购买 nike

我想尝试根据fieldName找出所有的fieldValue

MNC.java:

private Map <String, String>formFields = new HashMap<String, String>();

public void setFieldValue(String fieldName, String fieldValue) {
if (formFields == null) {
formFields = new HashMap<String, String>();
}
formFields.put(fieldName, fieldValue);

public Map<String, String> getFormFields() {
return formFields;
}
public void setFormFields(Map<String, String> formFields) {
this.formFields = formFields;

public String getFormField(String fieldName) {
if ((formFields != null) && (formFields.get(fieldName) != null)) {
return (String) formFields.get(fieldName);
}
return null;
}

MNC.hbm.xml:

<map name="formFields" table="mncformfields" cascade="all-delete-orphan" lazy="true">
<key column="id"/>
<index column="fieldName" type="string"/>
<element column="fieldValue" type="string"/>
</map>

这里是我的查询:

query.append("SELECT users.name,sum(mncfield.fieldValue) as TotalMoney");
query.append("from MNC as mnc ");
query.append("left join mnc.formFields as mncfield ");

query.append("with (mnc.mncID= mncfield.id) and (mnc field.fieldName = 'mapMoney') ");
query.append("left join mnc.serviceExec as users ");
query.append("where (mnc.mncID= mncfield.id) ");
query.append("and mnc.serviceExec.id=users.id ");
query.append("and (mnc.mncDate between :startDate and :endDate) ");
query.append("and (mnc.mncGroup.id in (:ugIDs)) ");
query.append("group by users.name");

我得到异常:

org.hibernate.hql.ast.QuerySyntaxException: unexpected token: with`

如果我评论这一行:

//query.append("with (mnc.mnc ID= mncfield.id) and (mnc field.fieldName = 'mapMoney') ");

然后我得到异常:

java.lang.IllegalArgumentException: org.hibernate.hql.ast.QuerySyntaxException: with-clause referenced two different from-clause elements

如果我使用 on 而不是 with 我得到:

org.hibernate.hql.ast.QuerySyntaxException: unexpected token: on

最佳答案

您是否注意到第一行末尾没有空格(应该在 TotalMoney 之后或以下 from 之前)?

关于java - Hibernate Exception 将 ON/WITH 条件应用于 LEFT JOIN,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4012431/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com