我收到以下錯誤,當我試圖通過一個共同的ID來執行連接查詢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]")
我想加入客戶和國家表一起
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>
Countries.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所以不知道有關的一切與它卻又是那麼沒有任何人知道如何解決這個查詢?
謝謝
如果你開始使用Hibernate我建議使用Java類與@Entity註解來建立你的Hibernate的東西。我不知道.xml的東西如何處理參數。 - 數據庫模式看起來像你期望的那樣嗎? – 2012-04-13 11:26:15
我正在使用它在我的課,我有它訪問數據庫,讀寫和所有這些,只是試圖讓這個JOIN QUERY工作是問題 – newSpringer 2012-04-13 11:39:05
DB模式看起來像你期望的那樣嗎? (Hibernate是否正確地創建了一個數據庫模式?) – 2012-04-13 11:41:44