当前位置: 代码迷 >> Java Web开发 >> 求一hibernate关联查询语句!该怎么处理
  详细解决方案

求一hibernate关联查询语句!该怎么处理

热度:85   发布时间:2016-04-17 10:54:27.0
求一hibernate关联查询语句!!!!!
package angel.domain;

public class Account {
private Long oid;
private String actNo;
private double bal;
private User owner;

public User getOwner() {
return owner;
}

public void setOwner(User owner) {
this.owner = owner;
}

public Account() {
super();
}

public Account(String actNo, double bal) {
super();
this.actNo = actNo;
this.bal = bal;
}
  public void withdraw(double amount){
  if(bal-amount>=0){
  bal = bal - amount;
  }
  }
  public void deposite(double amount){
  bal = bal + amount;
  }
public Long getOid() {
return oid;
}

public void setOid(Long oid) {
this.oid = oid;
}

public String getActNo() {
return actNo;
}

public void setActNo(String actNo) {
this.actNo = actNo;
}

public double getBal() {
return bal;
}

public void setBal(double bal) {
this.bal = bal;
}

@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((actNo == null) ? 0 : actNo.hashCode());
return result;
}

@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Account other = (Account) obj;
if (actNo == null) {
if (other.actNo != null)
return false;
} else if (!actNo.equals(other.actNo))
return false;
return true;
}
}

Account
<?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="angel.domain">
  <class name="Account" table="t_acct_one2many">
  <id name="oid" column="OID">
  <!--<generator class="seqhilo" />-->
  <generator class="native" />
  </id>
  <property name="actNo"
  column="ACTNO"
  not-null="true"
  unique="true" />
  <property name="bal"
  column="BALANCE"
  not-null="true" />
   
  <many-to-one name="owner"
  column="FID" />
   
   
   
   
   
   
  </class>
</hibernate-mapping>


package angel.domain;

import java.util.HashSet;
import java.util.Set;

public class User {
private Long oid;
private String uid;
private String name;
  private Set accts = new HashSet();

public void addAcct(Account acct){
accts.add(acct);
acct.setOwner(this);
}

public Set getAccts() {
return accts;
}

public void setAccts(Set accts) {
this.accts = accts;
}

public User() {
super();
}

public User(String uid, String name) {
super();
this.uid = uid;
this.name = name;
}

public Long getOid() {
return oid;
}
  相关解决方案