java代码:
StringBuffer hql = new StringBuffer("SELECT t FROM Citylist t, Employeecityref e  WHERE t.citycode = e.citycode and e.employeeid ='"+emp.getEmployeeid()+"'");
List<Citylist> list = getSession().createQuery(hql.toString()).list();出错信息:
org.hibernate.QueryException: could not resolve property: citycode of: com.palmcity.model.Employeecityref [SELECT t FROM com.palmcity.model.Citylist t, com.palmcity.model.Employeecityref e  WHERE t.citycode = e.citycode and employeeid ='35']
由于Employeecityref表中没有ID所以映射表有两个Employeecityref.java,EmployeecityrefID.java
请问我的HQL 语句怎么写才能把Citylist调出来

解决方案 »

  1.   

    org.hibernate.QueryException: could not resolve property: citycode of: com.palmcity.model.Employeecityref [SELECT t FROM com.palmcity.model.Citylist t, com.palmcity.model.Employeecityref e WHERE t.citycode = e.citycode and employeeid ='35']很明显不能处理citycode这个属性 Citylist 这个类里面有这个属性吗
      

  2.   

    报错里的citycode指的是Employeecityref里没有,而我的Employeecityref映身类是两个,一个Employeecityref.java,一个EmployeecityrefId.java,EmployeecityrefId.java里面有citycode可就是取不出来
      

  3.   

    也就是说你映射的是视图,现在用oracle可直接映射视图,不用映射多个对象那么麻烦,我就在用,不知道你用的什么数据库,其它的支持可能就要你的这种方法,要设置成序列化,复合主键
      

  4.   

    package com.palmcity.model;/**
     * Employeecityref entity. @author MyEclipse Persistence Tools
     */public class Employeecityref implements java.io.Serializable { // Fields private EmployeecityrefId id; // Constructors /** default constructor */
    public Employeecityref() {
    } /** full constructor */
    public Employeecityref(EmployeecityrefId id) {
    this.id = id;
    } // Property accessors public EmployeecityrefId getId() {
    return this.id;
    } public void setId(EmployeecityrefId id) {
    this.id = id;
    }}
    package com.palmcity.model;import java.math.BigDecimal;/**
     * EmployeecityrefId entity. @author MyEclipse Persistence Tools
     */public class EmployeecityrefId implements java.io.Serializable { // Fields private Long employeeid;
    private String citycode; // Constructors /** default constructor */
    public EmployeecityrefId() {
    } /** full constructor */
    public EmployeecityrefId(Long employeeid, String citycode) {
    this.employeeid = employeeid;
    this.citycode = citycode;
    } // Property accessors public Long getEmployeeid() {
    return this.employeeid;
    } public void setEmployeeid(Long employeeid) {
    this.employeeid = employeeid;
    } public String getCitycode() {
    return this.citycode;
    } public void setCitycode(String citycode) {
    this.citycode = citycode;
    } public boolean equals(Object other) {
    if ((this == other))
    return true;
    if ((other == null))
    return false;
    if (!(other instanceof EmployeecityrefId))
    return false;
    EmployeecityrefId castOther = (EmployeecityrefId) other; return ((this.getEmployeeid() == castOther.getEmployeeid()) || (this
    .getEmployeeid() != null
    && castOther.getEmployeeid() != null && this.getEmployeeid()
    .equals(castOther.getEmployeeid())))
    && ((this.getCitycode() == castOther.getCitycode()) || (this
    .getCitycode() != null
    && castOther.getCitycode() != null && this
    .getCitycode().equals(castOther.getCitycode())));
    } public int hashCode() {
    int result = 17; result = 37
    * result
    + (getEmployeeid() == null ? 0 : this.getEmployeeid()
    .hashCode());
    result = 37 * result
    + (getCitycode() == null ? 0 : this.getCitycode().hashCode());
    return result;
    }}
    <?xml version="1.0" encoding="utf-8"?>
    <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
    <!-- 
        Mapping file autogenerated by MyEclipse Persistence Tools
    -->
    <hibernate-mapping>
        <class name="com.palmcity.model.Employeecityref" table="EMPLOYEECITYREF" schema="TRAFFICS">
            <composite-id name="id" class="com.palmcity.model.EmployeecityrefId">
                <key-property name="employeeid" type="java.lang.Long">
                    <column name="EMPLOYEEID" precision="22" scale="0" />
                </key-property>
                <key-property name="citycode" type="java.lang.String">
                    <column name="CITYCODE" length="20" />
                </key-property>
            </composite-id>
        </class>
    </hibernate-mapping>这是类映射文件
      

  5.   

    尽管大家没有帮到我,但是还要谢谢大家,我解决了
    是这样的:From a where a.id.citycode='11'