|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 您现在的位置 >首页>IT技术社区>软件应用>正文 |
| [JAVA] 通过在PO中加入XDoclet,自动生成hbm配置文件 |
|
|
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" */ 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; 责任编辑:admin |
| 上一篇:[J2EE] J2EE乱码问题解决方案汇总 |
| 下一篇:关于Java初学者需要了解的几个基础问题 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 友情链接 |
甘肃IT在线热忱欢迎各类网站友情链接,首页链接要求:PR>=4,PR低的我们将全部调整至内页,还望见谅,谢谢合作! |
|
|
|
|
|
|
|