<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    sclsch

    java備忘

    BlogJava 首頁 新隨筆 聯系 聚合 管理
      10 Posts :: 0 Stories :: 6 Comments :: 0 Trackbacks
    種類Sort與勘誤Errata是一對多的關系.
    Sort.java
    package com.daacc.dao.sort;

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

    import com.daacc.dao.teacher.Teacher;

    /**
     * Sort generated by MyEclipse Persistence Tools
     
    */

    public class Sort implements java.io.Serializable {

        
    // Fields

        
    private Integer id;

        
    private Integer parentId;

        
    private String name;

        
    private String description;

        
    private Set erratas=new HashSet();

        
    // Constructors

        
    /** default constructor */
        
    public Sort() {
        }

        
    /** minimal constructor */
        
    public Sort(Integer id) {
            
    this.id = id;
        }

        
    /** full constructor */
        
    public Sort(Integer id, Integer parentid, String name, String description) {
            
    this.id = id;
            
    this.parentId = parentid;
            
    this.name = name;
            
    this.description = description;
            
    // this.teachers = teachers;
        }

        
    // Property accessors

        
    public Integer getId() {
            
    return this.id;
        }

        
    public void setId(Integer id) {
            
    this.id = id;
        }

        
    public String getName() {
            
    return this.name;
        }

        
    public void setName(String name) {
            
    this.name = name;
        }

        
    public String getDescription() {
            
    return this.description;
        }

        
    public void setDescription(String description) {
            
    this.description = description;
        }

        
    public Integer getParentId() {
            
    return parentId;
        }

        
    public void setParentId(Integer parentId) {
            
    this.parentId = parentId;
        }

        
    public Set getErratas() {
            
    return erratas;
        }

        
    public void setErratas(Set erratas) {
            
    this.erratas = erratas;
        }

        @Override
        
    public int hashCode() {
            
    final int PRIME = 31;
            
    int result = super.hashCode();
            result 
    = PRIME * result + ((description == null? 0 : description.hashCode());
            result 
    = PRIME * result + ((id == null? 0 : id.hashCode());
            result 
    = PRIME * result + ((name == null? 0 : name.hashCode());
            result 
    = PRIME * result + ((parentId == null? 0 : parentId.hashCode());
            
    return result;
        }

        @Override
        
    public boolean equals(Object obj) {
            
    if (this == obj)
                
    return true;
            
    if (!super.equals(obj))
                
    return false;
            
    if (getClass() != obj.getClass())
                
    return false;
            
    final Sort other = (Sort) obj;
            
    if (description == null) {
                
    if (other.description != null)
                    
    return false;
            } 
    else if (!description.equals(other.description))
                
    return false;
            
    if (id == null) {
                
    if (other.id != null)
                    
    return false;
            } 
    else if (!id.equals(other.id))
                
    return false;
            
    if (name == null) {
                
    if (other.name != null)
                    
    return false;
            } 
    else if (!name.equals(other.name))
                
    return false;
            
    if (parentId == null) {
                
    if (other.parentId != null)
                    
    return false;
            } 
    else if (!parentId.equals(other.parentId))
                
    return false;
            
    return true;
        }

    }

    Sort.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="com.daacc.dao.sort.Sort" table="sort">
            
    <id name="id" type="integer">
                
    <column name="id" />
                
    <generator class="native" />
            
    </id>

            
    <property name="parentId" type="integer">
                
    <column name="parent_id" not-null="true" />
            
    </property>
            
    <property name="name" type="string">
                
    <column name="name" length="30" />
            
    </property>
            
    <property name="description" type="string">
                
    <column name="description" length="300" />
            
    </property>
            
    <set name="erratas" inverse="false" lazy="true"
                cascade
    ="all-delete-orphan" outer-join="true">
                
    <key>
                    
    <column name="sort_id" not-null="true" />
                
    </key>
                
    <one-to-many class="com.daacc.dao.errata.Errata" />
            
    </set>

        
    </class>

    </hibernate-mapping>

    Errata.java
    package com.daacc.dao.errata;

    import java.util.Date;

    import com.daacc.dao.question.Question;
    import com.daacc.dao.sort.Sort;

    /**
     * Errata generated by MyEclipse Persistence Tools
     
    */

    public class Errata implements java.io.Serializable {

        
    // Fields

        
    private Integer id;



        
    private Question question;

        
    private String page;

        
    private String description;

        
    private String source;

        
    private String correct;

        
    private Date date;

        
    private String state;

        
    private Sort sort;

        
    // Constructors

        
    /** default constructor */
        
    public Errata() {
        }

        
    public Errata(Integer id) {
            
    this.id = id;
        }

        
    /** full constructor */
        
    public Errata(Question question, String page, String description,
                String source, String correct, Date date, String state) {
            
    this.question = question;
            
    this.page = page;
            
    this.description = description;
            
    this.source = source;
            
    this.correct = correct;
            
    this.date = date;
            
    this.state = state;
        }

        
    // Property accessors

        
    public Integer getId() {
            
    return this.id;
        }

        
    public void setId(Integer id) {
            
    this.id = id;
        }

        
    public String getPage() {
            
    return this.page;
        }

        
    public void setPage(String page) {
            
    this.page = page;
        }

        
    public String getDescription() {
            
    return this.description;
        }

        
    public void setDescription(String description) {
            
    this.description = description;
        }

        
    public String getSource() {
            
    return this.source;
        }

        
    public void setSource(String source) {
            
    this.source = source;
        }

        
    public String getCorrect() {
            
    return this.correct;
        }

        
    public void setCorrect(String correct) {
            
    this.correct = correct;
        }

        
    public Date getDate() {
            
    return this.date;
        }

        
    public void setDate(Date date) {
            
    this.date = date;
        }

        
    public String getState() {
            
    return this.state;
        }

        
    public void setState(String state) {
            
    this.state = state;
        }

        
    public Question getQuestion() {
            
    return question;
        }

        
    public void setQuestion(Question question) {
            
    this.question = question;
        }

        
    public Sort getSort() {
            
    return sort;
        }

        
    public void setSort(Sort sort) {
            
    this.sort = sort;
        }

        @Override
        
    public int hashCode() {
            
    final int PRIME = 31;
            
    int result = super.hashCode();
            result 
    = PRIME * result + ((correct == null? 0 : correct.hashCode());
            result 
    = PRIME * result + ((date == null? 0 : date.hashCode());
            result 
    = PRIME * result + ((description == null? 0 : description.hashCode());
            result 
    = PRIME * result + ((id == null? 0 : id.hashCode());
            result 
    = PRIME * result + ((page == null? 0 : page.hashCode());
            result 
    = PRIME * result + ((question == null? 0 : question.hashCode());
            result 
    = PRIME * result + ((source == null? 0 : source.hashCode());
            result 
    = PRIME * result + ((state == null? 0 : state.hashCode());
            
    return result;
        }

        @Override
        
    public boolean equals(Object obj) {
            
    if (this == obj)
                
    return true;
            
    if (!super.equals(obj))
                
    return false;
            
    if (getClass() != obj.getClass())
                
    return false;
            
    final Errata other = (Errata) obj;
            
    if (correct == null) {
                
    if (other.correct != null)
                    
    return false;
            } 
    else if (!correct.equals(other.correct))
                
    return false;
            
    if (date == null) {
                
    if (other.date != null)
                    
    return false;
            } 
    else if (!date.equals(other.date))
                
    return false;
            
    if (description == null) {
                
    if (other.description != null)
                    
    return false;
            } 
    else if (!description.equals(other.description))
                
    return false;
            
    if (id == null) {
                
    if (other.id != null)
                    
    return false;
            } 
    else if (!id.equals(other.id))
                
    return false;
            
    if (page == null) {
                
    if (other.page != null)
                    
    return false;
            } 
    else if (!page.equals(other.page))
                
    return false;
            
    if (question == null) {
                
    if (other.question != null)
                    
    return false;
            } 
    else if (!question.equals(other.question))
                
    return false;
            
    if (source == null) {
                
    if (other.source != null)
                    
    return false;
            } 
    else if (!source.equals(other.source))
                
    return false;
            
    if (state == null) {
                
    if (other.state != null)
                    
    return false;
            } 
    else if (!state.equals(other.state))
                
    return false;
            
    return true;
        }



    }

    Errata.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 Persistence Tools
    -->
    <hibernate-mapping>
        
    <class name="com.daacc.dao.errata.Errata" table="errata">
            
    <id name="id" type="java.lang.Integer">
                
    <column name="id" />
                
    <generator class="native"></generator>
            
    </id>
            
    <many-to-one name="question"
                class
    ="com.daacc.dao.question.Question" fetch="select">
                
    <column name="question_id" not-null="true" unique="true" />
            
    </many-to-one>
            
    <many-to-one name="sort" cascade="save-update" outer-join="auto"
                class
    ="com.daacc.dao.sort.Sort">
                
    <column name="sort_id" />
            
    </many-to-one>
            
    <property name="page" type="java.lang.String">
                
    <column name="page" length="11" />
            
    </property>
            
    <property name="description" type="java.lang.String">
                
    <column name="description" length="300" />
            
    </property>
            
    <property name="source" type="java.lang.String">
                
    <column name="source" length="200" />
            
    </property>
            
    <property name="correct" type="java.lang.String">
                
    <column name="correct" length="300" />
            
    </property>
            
    <property name="date" type="java.util.Date">
                
    <column name="date" length="10" />
            
    </property>
            
    <property name="state" type="java.lang.String">
                
    <column name="state" length="11" />
            
    </property>


        
    </class>
    </hibernate-mapping>

    GetErrtaBySortAction.java
    /*
     * Generated by MyEclipse Struts
     * Template path: templates/java/JavaClass.vtl
     
    */
    package com.daacc.web.errata;

    import java.util.ArrayList;
    import java.util.Iterator;
    import java.util.List;
    import java.util.Set;

    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    import org.apache.struts.action.Action;
    import org.apache.struts.action.ActionForm;
    import org.apache.struts.action.ActionForward;
    import org.apache.struts.action.ActionMapping;

    import com.daacc.dao.sort.Sort;
    import com.daacc.facade.*;
    import com.daacc.dao.errata.*;

    /**
     * MyEclipse Struts Creation date: 07-09-2007
     * 
     * XDoclet definition:
     * 
     * @struts.action validate="true"
     * @struts.action-forward name="success"
     *                        path="/WEB-INF/jsp/userarea/err/errata.jsp"
     
    */
    public class GetErrtaBySortAction extends Action {
        
    /*
         * Generated Methods
         
    */

        
    /**
         * Method execute
         * 
         * 
    @param mapping
         * 
    @param form
         * 
    @param request
         * 
    @param response
         * 
    @return ActionForward
         
    */
        
    public ActionForward execute(ActionMapping mapping, ActionForm form,
                HttpServletRequest request, HttpServletResponse response) {
            String sortId 
    = request.getParameter("sortId");
            System.out.println(
    "sortId:" + sortId);
            Sort sort 
    = (Sort) BusFacade.sortBus.getSort(Integer.parseInt(sortId));
            Set set 
    = sort.getErratas();
            Iterator it 
    = set.iterator();
            List errList 
    = new ArrayList();
            
    while (it.hasNext()) {
                errList.add(it.next());
            }
            request.setAttribute(
    "errList", errList);
            
    for (int i = 0; i < errList.size(); i++) {
                Errata errata 
    = (Errata) errList.get(i);
                System.out.println(errata.getId());
                System.out.println(
    "errata.getDescription():"
                        
    + errata.getDescription());
            }
            
    return mapping.findForward("success");
        }
    }

    業務層代碼

     

        public Sort getSort(int id) {

            Sort sort 
    = null;

            
    try {
                sort 
    = sortDao.get(new Integer(id));
            } 
    catch (Exception e) {
                e.printStackTrace();

            }

            
    return sort;

        }

     SortDAOImp.java

        public Sort get(Integer id) {
            
    return (Sort) getHibernateTemplate().get(Sort.class, id);
        }
    posted on 2007-07-10 20:04 sclsch 閱讀(3087) 評論(1)  編輯  收藏

    Feedback

    # re: hibernate多對一關系的配置及操作 2009-05-31 17:32 嘎嘎
    也不用中文標識一下  回復  更多評論
      


    只有注冊用戶登錄后才能發表評論。


    網站導航:
     
    主站蜘蛛池模板: 青青操在线免费观看| 91免费在线播放| 国产成人免费高清激情明星| 99视频在线精品免费观看6| 男人和女人高潮免费网站| 亚洲成AV人片一区二区| 亚洲视频在线观看| 亚洲精品视频免费| 99久久亚洲综合精品成人网| 最新亚洲人成无码网www电影| 亚洲一级片免费看| 久久成人免费电影| 国产黄色片在线免费观看| 亚洲一级片免费看| 天天爽亚洲中文字幕| 深夜a级毛片免费无码| 色噜噜AV亚洲色一区二区| 亚洲成a人片在线观看精品| 毛片免费视频在线观看| 亚洲国产精品免费视频| 99爱免费观看视频在线| 亚洲&#228;v永久无码精品天堂久久 | 美女视频黄的免费视频网页 | 久久免费国产精品一区二区| 亚洲国语精品自产拍在线观看| 91免费在线播放| 国产偷国产偷亚洲高清人| 成人免费毛片观看| 一级黄色片免费观看| 日本不卡视频免费| 你懂的在线免费观看| 亚洲国产成AV人天堂无码| 久久免费精品一区二区| 亚洲一区二区三区播放在线| 国产激情免费视频在线观看| 亚洲 欧洲 视频 伦小说| 免费成人福利视频| 羞羞视频免费网站含羞草| 日韩免费视频网站| 野花香在线视频免费观看大全| 亚洲国产av一区二区三区丶|