one-to-many:
Userinfo.java
- package airticket.po;
- import java.util.HashSet;
- import java.util.Set;
- /**
- * Userinfo generated by MyEclipse - Hibernate Tools
- */
- @SuppressWarnings("serial")
- public class Userinfo implements java.io.Serializable {
- // Fields
- private Long userid;
- private String username;
- private String pasword;
- private Set userscores = new HashSet(0);
- // Constructors
- /** default constructor */
- public Userinfo() {
- }
- /** full constructor */
- public Userinfo(Long userid, String username, String pasword, Set userscores){
- this.username = username;
- this.pasword = pasword;
- this.userscores = userscores;
- }
- // Property accessors
- public Long getUserid() {
- return this.userid;
- }
- public void setUserid(Long userid) {
- this.userid = userid;
- }
- public String getUsername() {
- return this.username;
- }
- public void setUsername(String username) {
- this.username = username;
- }
- public String getPasword() {
- return this.pasword;
- }
- public void setPasword(String pasword) {
- this.pasword = pasword;
- }
- public Set getUserscores() {
- return userscores;
- }
- public void setUserscores(Set userscores) {
- this.userscores = userscores;
- }
- }
对应关系存放在Set中
private Set userscores = new HashSet(0);
Userinfo.hbm.xml
- <?xml version="1.0" encoding="utf-8"?>
- <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
- "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
- <!--
- Mapping file autogenerated by MyEclipse - Hibernate Tools
- -->
- <hibernate-mapping>
- <class name="airorder.Userinfo" table="USERINFO" schema="TICKET">
- <id name="userid" type="java.lang.Long">
- <column name="USERID" precision="22" scale="0" />
- <generator class="assigned"></generator>
- </id>
- <property name="username" type="java.lang.String">
- <column name="USERNAME" length="12" not-null="true" />
- </property>
- <property name="pasword" type="java.lang.String">
- <column name="PASWORD" length="32" />
- </property>
- <set name="userscores" inverse="true">
- <key>
- <column name="USERID" precision="22" scale="0" not-null="true" />
- </key>
- <one-to-many class="airticket.po.Userscore" />
- </set>
- </class>
- </hibernate-mapping>
对应关系存放在<set>标签对中
<set name="userscores" inverse="true">
<key>
<column name="USERID" precision="22" scale="0" not-null="true" />
</key>
<one-to-many class="airticket.po.Userscore" />
</set>
many-to-one:
Userscore.java
- package airticket.po;
- import java.util.Date;
- /**
- * Userscore generated by MyEclipse - Hibernate Tools
- */
- @SuppressWarnings("serial")
- public class Userscore implements java.io.Serializable {
- // Fields
- private String scoreid;
- private Userinfo userinfo;
- private String username;
- private Long obtainscore;
- private Long costscore;
- private Date updscotime;
- private String orderid;
- private String eventid;
- // Constructors
- /** default constructor */
- public Userscore() {
- }
- /** minimal constructor */
- public Userscore(String scoreid, Userinfo userinfo, String username, Date updscotime) {
- this.scoreid = scoreid;
- this.userinfo = userinfo;
- this.username = username;
- this.updscotime = updscotime;
- }
- /** full constructor */
- public Userscore(String scoreid, Userinfo userinfo, String username, Long obtainscore, Long costscore, Date updscotime, String orderid, String eventid) {
- this.scoreid = scoreid;
- this.userinfo = userinfo;
- this.username = username;
- this.obtainscore = obtainscore;
- this.costscore = costscore;
- this.updscotime = updscotime;
- this.orderid = orderid;
- this.eventid = eventid;
- }
- // Property accessors
- public String getScoreid() {
- return this.scoreid;
- }
- public void setScoreid(String scoreid) {
- this.scoreid = scoreid;
- }
- public Userinfo getUserinfo() {
- return this.userinfo;
- }
- public void setUserinfo(Userinfo userinfo) {
- this.userinfo = userinfo;
- }
- public String getUsername() {
- return this.username;
- }
- public void setUsername(String username) {
- this.username = username;
- }
- public Long getObtainscore() {
- return this.obtainscore;
- }
- public void setObtainscore(Long obtainscore) {
- this.obtainscore = obtainscore;
- }
- public Long getCostscore() {
- return this.costscore;
- }
- public void setCostscore(Long costscore) {
- this.costscore = costscore;
- }
- public Date getUpdscotime() {
- return this.updscotime;
- }
- public void setUpdscotime(Date updscotime) {
- this.updscotime = updscotime;
- }
- public String getOrderid() {
- return this.orderid;
- }
- public void setOrderid(String orderid) {
- this.orderid = orderid;
- }
- public String getEventid() {
- return this.eventid;
- }
- public void setEventid(String eventid) {
- this.eventid = eventid;
- }
- }
对应关系保存在类中
private Userinfo userinfo;
Userscore.hbm.xml
- <?xml version="1.0" encoding="utf-8"?>
- <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
- "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
- <!--
- Mapping file autogenerated by MyEclipse - Hibernate Tools
- -->
- <hibernate-mapping>
- <class name="airorder.Userscore" table="USERSCORE" schema="TICKET">
- <id name="scoreid" type="java.lang.String">
- <column name="SCOREID" length="32" />
- <generator class="assigned"></generator>
- </id>
- <many-to-one name="userinfo" class="airticket.po.Userinfo" fetch="select">
- <column name="USERID" precision="22" scale="0" not-null="true" />
- </many-to-one>
- <property name="username" type="java.lang.String">
- <column name="USERNAME" length="12" not-null="true" />
- </property>
- <property name="obtainscore" type="java.lang.Long">
- <column name="OBTAINSCORE" precision="22" scale="0" />
- </property>
- <property name="costscore" type="java.lang.Long">
- <column name="COSTSCORE" precision="22" scale="0" />
- </property>
- <property name="updscotime" type="java.util.Date">
- <column name="UPDSCOTIME" length="7" not-null="true" />
- </property>
- <property name="orderid" type="java.lang.String">
- <column name="ORDERID" length="32" />
- </property>
- <property name="eventid" type="java.lang.String">
- <column name="EVENTID" length="32" />
- </property>
- </class>
- </hibernate-mapping>
对应关系保存在<many-to-one>标签对中
<many-to-one name="userinfo" class="airticket.po.Userinfo" fetch="select">
<column name="USERID" precision="22" scale="0" not-null="true" />
</many-to-one>