`

hibernate关系映射

阅读更多

1:多对一:create table T_USER_CODEPOINT
(
  ID           NUMBER(20) not null,
  REMAIN_POINT NUMBER(8,2),
  CLIENT_ID    NUMBER(20)              外键,对应 Client表,
)

  <!-- bi-directional many-to-one association to Publisher --> hbm.xml文件,
  <many-to-one
        name="client"
        class="com.erry.mag.model.Client"
        not-null="true"
    >
        <meta attribute="use-in-equals">true</meta>
        <column name="CLIENT_ID" />
    </many-to-one>                

java文件,

com.erry.mag.model.Client client;

 public com.erry.mag.model.Client getClient() {
  return client;
 }

 public void setClient(com.erry.mag.model.Client client) {
  this.client = client;
 }

查询语句:String hql2 = "select u from com.erry.mag.model.UserCodePoint u,com.erry.mag.model.Client c  where u.client=c and c.id=:id";

2:一对一:

3:多对多:

               

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics