Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java HQL联接查询:无法解析属性:_Java_Spring_Hibernate_Hql - Fatal编程技术网

Java HQL联接查询:无法解析属性:

Java HQL联接查询:无法解析属性:,java,spring,hibernate,hql,Java,Spring,Hibernate,Hql,当我尝试执行联接查询时,出现以下错误 ("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表和Countrie

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

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

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>
我是HQL的新手,所以还不能确定它的一切,所以有人知道如何解决这个问题吗


谢谢

是美国,不是美国。属性名称区分大小写。

请尝试

select cus from Customer cus  where cus.id = cus.countries.id

如果从Hibernate开始,我建议使用带有@Entity注释的Java类来构建Hibernate。我不知道.xml是如何处理参数的db模式看起来像你所期望的吗?我在我的类中使用它,我让它访问数据库,读写以及所有这些,只是试图让这个连接查询工作是问题db模式看起来像你所期望的吗?(Hibernate是否正确地创建了一个DB模式?)是的,就是这样,但它没有工作。。。但是我将它声明为国家,所以它应该不重要吗?在Customer类中,您可能有一些类似getCountries和setCountries的内容。这意味着属性是国家(小写)。您应该更改Customer.hbm.xml以反映这一点。您的变量名是
国家/地区
?然后使用
cus.Countries.id
String sql_query = "select cus from Customer as cus join cus.Countries as cou where cus.id = cou.id";
select cus from Customer cus  where cus.id = cus.countries.id