操作hibernate多主鍵的問題?
各位大蝦:
現在有個關於hibernate多主鍵的問題,請指教:
一個表Result,有兩個主鍵,分別是customerId,setDate,用Middlegen Hibernate plugin生成一個單獨的主鍵類ResultPK.
下面是從資料庫生成的result.hbm.xml檔案:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >
<hibernate-mapping>
<!--
Created by Middlegen Hibernate plugin
http://boss.bekk.no/boss/middlegen/
http://hibernate.sourceforge.net/
-->
<class
name="com.persistent.Result" table="result"
>
<composite-id name="comp_id" class="com.persistent.ResultPK">
<key-property name="customerId" column="customerID" type="java.lang.String" />
<key-property name="setDate" column="setDate" type="java.lang.String" />
</composite-id>
<property
name="degree"
type="int"
column="degree"
length="3"
/>
<property
name="prize"
type="java.lang.String"
column="prize"
not-null="true"
length="2"
/>
<property
name="wage"
type="int"
column="wage"
not-null="true"
length="5"
/>
<property
name="train"
type="int"
column="train"
not-null="true"
length="2"
/>
<!-- associations -->
</class>
</hibernate-mapping>
現在我想查詢表中所有customerId='0001' and setDate='2003-08-12' 的記錄,怎麼寫HQL語句???,急死我了!
我寫的HQL語句:
//首先給主鍵類賦值
ResultPK resultPK = new ResultPK(); //結算主鍵表
resultPK.setCustomerId("0001");
resultPK.setSetDate("2003-08-12");
//注:comp_id是Result類中ResultPK的例項
//在Result類中有 public ResultPK getComp_id() {}
// public void setComp_id(ResultPK comp_id) {} 方法。
下面是我寫的hql語句:
session.find("select result.comp_id from Result result where result.comp_id = "+resultPK+" ");
但是執行時出現錯誤:就在session.find(....)那行出錯:
net.sf.hibernate.QueryException: path expression ends in a composite value: result0_.comp_id [select result.comp_id from com.persistent.Result result where result.comp_id = com.persistent.ResultPK@11946c2[customerId=0001,setDate=2003-08-12] ]
我不知道這樣的語句怎麼寫?請大家幫幫忙!
先謝了。
現在有個關於hibernate多主鍵的問題,請指教:
一個表Result,有兩個主鍵,分別是customerId,setDate,用Middlegen Hibernate plugin生成一個單獨的主鍵類ResultPK.
下面是從資料庫生成的result.hbm.xml檔案:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >
<hibernate-mapping>
<!--
Created by Middlegen Hibernate plugin
http://boss.bekk.no/boss/middlegen/
http://hibernate.sourceforge.net/
-->
<class
name="com.persistent.Result" table="result"
>
<composite-id name="comp_id" class="com.persistent.ResultPK">
<key-property name="customerId" column="customerID" type="java.lang.String" />
<key-property name="setDate" column="setDate" type="java.lang.String" />
</composite-id>
<property
name="degree"
type="int"
column="degree"
length="3"
/>
<property
name="prize"
type="java.lang.String"
column="prize"
not-null="true"
length="2"
/>
<property
name="wage"
type="int"
column="wage"
not-null="true"
length="5"
/>
<property
name="train"
type="int"
column="train"
not-null="true"
length="2"
/>
<!-- associations -->
</class>
</hibernate-mapping>
現在我想查詢表中所有customerId='0001' and setDate='2003-08-12' 的記錄,怎麼寫HQL語句???,急死我了!
我寫的HQL語句:
//首先給主鍵類賦值
ResultPK resultPK = new ResultPK(); //結算主鍵表
resultPK.setCustomerId("0001");
resultPK.setSetDate("2003-08-12");
//注:comp_id是Result類中ResultPK的例項
//在Result類中有 public ResultPK getComp_id() {}
// public void setComp_id(ResultPK comp_id) {} 方法。
下面是我寫的hql語句:
session.find("select result.comp_id from Result result where result.comp_id = "+resultPK+" ");
但是執行時出現錯誤:就在session.find(....)那行出錯:
net.sf.hibernate.QueryException: path expression ends in a composite value: result0_.comp_id [select result.comp_id from com.persistent.Result result where result.comp_id = com.persistent.ResultPK@11946c2[customerId=0001,setDate=2003-08-12] ]
我不知道這樣的語句怎麼寫?請大家幫幫忙!
先謝了。
相關文章
- hibernate中的no session問題Session
- [20210520]關於主鍵索引問題.txt索引
- MySQL自增主鍵跳號問題MySql
- Hibernate 一個更新問題的 討論
- 使用Hibernate、JPA、Lombok遇到的有趣問題Lombok
- 主鍵的建立、新增、刪除操作
- oracle 序列值導致的主鍵衝突問題Oracle
- 記SqlSugar ORM框架之找不到主鍵問題SqlSugarORM框架
- hibernate中多對多關係的維護
- 解決Spring Data JPA Hibernate的N+1問題的最佳方法Spring
- 【MySQL】gh-ost改雙主表結構主鍵衝突問題MySql
- 6.Hibernate多對多關係建立
- Binder關鍵問題
- git 操作遇到問題Git
- 多程式問題
- Java操作hdfs出現的問題Java
- 多語言遇到的問題
- Hibernate最全面試題面試題
- 解決HIbernate分頁問題獲取表總行數的小Bug
- Rancher 2022 關鍵主題與新年展望
- 關於操作駁回遇到的問題
- Android夜間模式(多主題)探索Android模式
- 你可能忽略的多型問題多型
- Hibernate 基本操作、懶載入以及快取快取
- App 多區域皮膚(主題)的實現APP
- hibernate一對多、多對多的實體設計和配置檔案配置
- mysql主從同步問題整理MySql主從同步
- 主元素問題(C語言)C語言
- spring-data-jpa一對多、多對多雙向關聯,查詢操作的時候進入死迴圈問題Spring
- 同文輸入法更換鍵盤主題
- 看懂js中this關鍵字的指向問題JS
- Java併發指南3:併發三大問題與volatile關鍵字,CAS操作Java
- git的一些常用操作和問題Git
- 關於JQuery操作checkbox問題jQuery
- MyBatis的Insert操作自增主鍵的實現,Mysql協議與JDBC實現MyBatisMySql協議JDBC
- mysql多版本共存問題MySql
- python合併多個csv檔案需要注意的問題(合併多個列名問題)Python
- MySQL新增列、刪除列,建立主鍵等常用操作總結MySql
- 主鍵命名