Hibernate Exception applying ON/WITH condition to LEFT JOIN
i want to try to find out all the fieldValue based on fieldName
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.开发者_Python百科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>
here my query:
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");
I get exception:
org.hibernate.hql.ast.QuerySyntaxException: unexpected token: with`
If i comment this line:
//query.append("with (mnc.mnc ID= mncfield.id) and (mnc field.fieldName = 'mapMoney') ");
then I get the exception:
java.lang.IllegalArgumentException: org.hibernate.hql.ast.QuerySyntaxException: with-clause referenced two different from-clause elements
If i use on instead of with I get:
org.hibernate.hql.ast.QuerySyntaxException: unexpected token: on
Did you notice that you don't have a space at the end of the first line (should be after TotalMoney or before the following from)?
 
         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论