Hibernate利用XDoclet自动生成配置文件

Hibernate利用XDoclet自动生成配置文件
作者: 发布时间:2008-07-22 10:05:51 来源:育路计算机考试频道
many- to-many为例,有Position和User两张表,一个Position可以有多个Users,一个User也可以有多个 Position,中间的关联表为 test_user_position 。通过在PO中加入XDoclet,自动生成hbm配置文件。不废话,看代码。

  package test;

  import java.util.Set;

  import java.util.TreeSet;

  /** *//**

  * @hibernate.class table="test_position"

  */

  public class Position ...{

  private int id;

  private int name;

  private Set<Users> users = new TreeSet<Users>();

  /** *//**

  * @hibernate.id generator-class="identity" type="int"

  */

  public int getId() ...{

  return id;

  }

  public void setId(int id) ...{

  this.id = id;

  }

  /** *//**

  * @hibernate.property length="25"

  */

  public int getName() ...{

  return name;

  }

  public void setName(int name) ...{

  this.name = name;

  }

  /** *//**

  * @hibernate.set inverse="true" lazy="true" table="test_user_position"

  * @hibernate.collection-key column="position_id"

  * @hibernate.collection-many-to-many class="test.Users" column="user_id"

  */

  public Set<Users> getUsers() ...{

  return users;

  }

  public void setUsers(Set<Users> users) ...{

  this.users = users;

  }

  }

  package test;

  import java.util.Set;

  import java.util.TreeSet;

  /** *//**

  * @hibernate.class <A title=table href="http://www.alimama.com/membersvc/buyadzone/buy_ad_zone.htm?adzoneid=892989 " target=_blank>table</A>="test_position"

  */ 转 public class Position ...{

  private int id;

  private int name;

  private Set<Users> users = new TreeSet<Users>();

  /** *//**

  * @hibernate.id generator-class="identity" type="int"

  */

  public int getId() ...{

  return id;

  }

  public void setId(int id) ...{

  this.id = id;

  }

  /** *//**

  * @hibernate.property length="25"

  */

  public int getName() ...{

  return name;

  }

  public void setName(int name) ...{

  this.name = name;

  }

  /** *//**

  * @hibernate.set inverse="true" lazy="true" <A title=table href="http://www.alimama.com/membersvc/buyadzone/buy_ad_zone.htm?adzoneid=892989 " target=_blank>table</A>="test_user_position"

  * @hibernate.collection-key column="position_id"

  * @hibernate.collection-many-to-many class="test.Users" column="user_id"

  */

  public Set<Users> getUsers() ...{

  return users;

  }

  public void setUsers(Set<Users> users) ...{

  this.users = users;

  }

  }

  package test;

  import java.util.Set;

  import java.util.TreeSet;

  /** *//**

  * @hibernate.class table="test_position"

  */

  public class Position ...{

  private int id;

  

  private int name;

  private Set<Users> users = new TreeSet<Users>();

  /** *//**

  * @hibernate.id generator-class="identity" type="int"

  */

  public int getId() ...{

  return id;

  }

  public void setId(int id) ...{

  this.id = id;

  }

  /** *//**

  * @hibernate.property length="25"

  */

  public int getName() ...{

  return name;

  }

  public void setName(int name) ...{

  this.name = name;

  }

  /** *//**

  * @hibernate.set inverse="true" lazy="true" table="test_user_position"

  * @hibernate.collection-key column="position_id"

  * @hibernate.collection-many-to-many class="test.Users" column="user_id"

贴于:Java认证考试_考试大
public Set<Users> getUsers() ...{

  return users;

  }

  public void setUsers(Set<Users> users) ...{

  this.users = users;

  }

  }

  接下来是Users.java

  

  Java代码

  package test;

  import java.util.*;

  /** *//**

  * @hibernate.class table="test_uses"

  */

  public class Users ...{

  private int id;

  private String name;

  private Set<Position> positions = new TreeSet<Position>();

  /** *//**

  * @hibernate.id generator-class="identity" typ="int"

  */

  public int getId() ...{

  return id;

  }

  public void setId(int id) ...{

  this.id = id;

  }

  /** *//**

  * @hibernate.property length="25"

  */

  public String getName() ...{

  return name;

  }

  public void setName(String name) ...{

  this.name = name;

  }

  /** *//**

  * @hibernate.set table="test_user_position" lazy="true"

  * @hibernate.collection-key column="user_id"

  * @hibernate.collection-many-to-many class="test.Position" column="position_id"

  */

  public Set<Position> getPositions() ...{

  return positions;

  }

  public void setPositions(Set<Position> positions) ...{

  this.positions = positions;

  }

  }

  view plaincopy to clipboardprint?

  package test;

  import java.util.*;

  /** *//**

  * @hibernate.class <A title=table href="http://www.alimama.com/membersvc/buyadzone/buy_ad_zone.htm?adzoneid=892989 " target=_blank>table</A>="test_uses"

  */

  public class Users ...{

  private int id;

  private String name;

  private Set<Position> positions = new TreeSet<Position>();

  /** *//**

  * @hibernate.id generator-class="identity" typ="int"

  */

  public int getId() ...{

  return id;

  }

  public void setId(int id) ...{

  this.id = id;

  }

  /** *//**

  * @hibernate.property length="25"

  */

  public String getName() ...{

  return name;

  }public void setName(String name) ...{

  this.name = name;

  }

  /** *//**

  * @hibernate.set <A title=table href="http://www.alimama.com/membersvc/buyadzone/buy_ad_zone.htm?adzoneid=892989 " target=_blank>table</A>="test_user_position" lazy="true"

  * @hibernate.collection-key column="user_id"

  * @hibernate.collection-many-to-many class="test.Position" column="position_id"

  */

  public Set<Position> getPositions() ...{

  return positions;

  }

  public void setPositions(Set<Position> positions) ...{

  this.positions = positions;

  }

  }

  package test;

  import java.util.*;

  /** *//**

  * @hibernate.class table="test_uses"

  */

  public class Users ...{

  private int id;

  private String name;

  private Set<Position> positions = new TreeSet<Position>();

  /** *//**

  * @hibernate.id generator-class="identity" typ="int"

  */

  public int getId() ...{

  return id;

  }

  public void setId(int id) ...{

  this.id = id;

  }

  /** *//**

  * @hibernate.property length="25"

  */

  public String getName() ...{

  return name;

  }

  public void setName(String name) ...{

  this.name = name;

  }

  /** *//**

  * @hibernate.set table="test_user_position" lazy="true"

  * @hibernate.collection-key column="user_id"

  * @hibernate.collection-many-to-many class="test.Position" column="position_id"

  */

  public Set<Position> getPositions() ...{

  return positions;

  }

  public void setPositions(Set<Position> positions) ...{

  this.positions = positions;

  }

  }
育路网
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值