尝试执行联接查询时出现以下错误

("could not resolve property: Countries of: com.fexco.helloworld.web.model.Customer [select cus from com.fexco.helloworld.web.model.Customer as cus join cus.Countries as cou where cus.id = cou.id]")


我正在尝试通过通用ID将“客户”和“国家/地区”表结合在一起

Customer.hbm.xml

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="com.ccg.db.test">
<class name="Customer" table="Customer">
    <id name="id" column="id" type="bigiint">
        <generator class="native"/>
    </id>
    <property name="firstname" type="string" >
       <column name="firstname" />
    </property>
    <property name="surname" type="string" >
        <column name="surname" />
    </property>
    <property name="address1" type="string" >
        <column name="address1" />
    </property>
    <property name="address2" type="string" >
        <column name="address2" />
    </property>
    <many-to-one name="Countries" column="id" class="Countries" />
</class>
</hibernate-mapping>


States.hbm.xml

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"   "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="com.ccg.db.test">
<!-- CLASS NAME MIGHT BE CUSTOMER -->
<class name="Countries" table="Countries">
    <id name="id" column="id">
        <generator class="native" />
    </id>
    <property name="country" column="country" />
</class>
</hibernate-mapping>


这是我试图调用的查询

String sql_query = "select cus from Customer as cus join cus.Countries as cou where cus.id = cou.id";


我是HQL的新手,因此尚不确定所有内容,因此有人知道如何解决此问题吗?

谢谢

最佳答案

它是cus.countries,而不是cus.Countries。属性名称区分大小写。

09-08 03:57