0

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

("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 和 Country 表连接在一起

客户.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>

国家.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 的新手,所以不确定它的一切,所以有人知道如何解决这个问题吗?

谢谢

4

2 回答 2

1

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

于 2012-04-13T11:27:38.330 回答
0

尝试

select cus from Customer cus  where cus.id = cus.countries.id
于 2012-04-13T11:27:43.400 回答