hibernate几种HQL的写法

本文探讨了如何使用HQL进行复杂的数据库查询,并通过示例展示了如何将查询结果映射到自定义的Java对象中,包括多个表的连接查询及结果集的封装。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1、"select new com.vnv.bank.mutualAccount.actionform.MutualSubAccountForm"
        + "(ab.accountName, ab.accountId , ab.provSeq , ab.citySeq , ab.bankName ,"
        +"sa.accountId , sa.accountName , sa.subAccountType , ab.bankInfo.id ,sa.id) " +
        " from SubAccount sa , AccountBank ab " +
        "where sa.accountBank = ab.id  and sa.id = " 

2、" select new  AccountQueryBean(s, a, t) from "
    + " SubAccount s ,Account a ,Transaction t "
    + "where (t.credit=s.id and s.account.id=a.id";

  其中a,s,f 分别是相应的POJO类,AccountQueryBean 结构如下

public class AcctBalHisBean {
 AcctBalHis a =null;
 SubAccount s =null; 
 SubAccount sa = null;
    Transaction t = null;
 
 public AcctBalHisBean (){}
 public AcctBalHisBean (AcctBalHis a,SubAccount s,SubAccount sa,Transaction t){
  this.a=a;
  this.s=s;
  this.sa = sa;
  this.t = t;
 
 }
 String accountId;
 String subAccountId;
 String balance;
 String lockAmount;
 String fee;
 String accountName;//对方帐户名称
 String otherSubAccountId;//对方子帐户id
    String thisAccountName;
    String amount;
 String transId;
 String upDate;
 String beginDate;
 String endDate;
 String startPage;
 String tid;
 String ttransId;
 
 public String getTtransId() {
  return t.getTransId();
 }
 public void setTtransId(String ttransId) {
  this.ttransId = ttransId;
 }
 public String getTid() {
  return t.getId()+"";
 }
 public void setTid(String tid) {
  this.tid = tid;
 }
 public Transaction getT() {
  return t;
 }
 public void setT(Transaction t) {
  this.t = t;
 }
 public AcctBalHis getA() {
  return a;
 }
 public void setA(AcctBalHis a) {
  this.a = a;
 }
 public String getAccountId() {
  return s.getAccountId();
 }
 public void setAccountId(String accountId) {
  this.accountId = accountId;
 }
 public String getAccountName() {
  return sa.getAccount().getName();
 }
 public void setAccountName(String accountName) {
  this.accountName = accountName;
 }
 public String getBalance() {
  return a.getBalance()+"";
 }
 public void setBalance(String balance) {
  this.balance = balance;
 }
 public String getFee() {
  return a.getFee()+"";
 }
 public void setFee(String fee) {
  this.fee = fee;
 }
 public String getLockAmount() {
  return a.getLockAmount()+"";
 }
 public void setLockAmount(String lockAmount) {
  this.lockAmount = lockAmount;
 }
 public SubAccount getS() {
  return s;
 }
 public void setS(SubAccount s) {
  this.s = s;
 }
 public SubAccount getSa() {
  return sa;
 }
 public void setSa(SubAccount sa) {
  this.sa = sa;
 }
 public String getSubAccountId() {
  return a.getId()+"";
 }
 public void setSubAccountId(String subAccountId) {
  this.subAccountId = subAccountId;
 }
 public String getTransId() {
  return a.getTransid()+"";
 }
 public void setTransId(String transId) {
  this.transId = transId;
 }
 public String getUpDate() {
  return a.getUpdateTime()+"";
 }
 public void setUpDate(String upDate) {
  this.upDate = upDate;
 }
 public String getAmount() {
  return a.getAmount()+"";
 }
 public void setAmount(String amount) {
  this.amount = amount;
 }
 public String getThisAccountName() {
  return s.getAccountName();
 }
 public void setThisAccountName(String thisAccountName) {
  this.thisAccountName = thisAccountName;
 }
 public String getOtherSubAccountId() {
  return sa.getAccount().getId()+"";
 }
 public void setOtherSubAccountId(String otherSubAccountId) {
  this.otherSubAccountId = otherSubAccountId;
 }
 
 }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值