Hibernate在文本字段中加载

时间:2016-08-03 13:55:32

标签: java swing hibernate

private void display() {
   Session session = NewHibernateUtil.getSessionFactory().openSession();
    session.beginTransaction();
    OrderEntry oe = (OrderEntry) session.load(OrderEntry.class, new Integer(2) );
    firstname_tf.setText(oe.getFirstname());
}

您好, 我想在GUI中从我的数据库中检索对象。我使用session.load,但我不确定如何将数据传输到GUI。我试过firstname_tf.setText(oe.getFirstname());但没有任何反应。可以请sombody帮助我。请原谅我的英语不好。

public static void main(String args []){

    /* Create and display the form */
    java.awt.EventQueue.invokeLater(new Runnable() {
        public void run() {
            new UpdateUI().setVisible(true);
        }
    });
}


public class OrderEntry  implements java.io.Serializable {

     private Integer orderid;
     private String reference;
     private String type;
     private String cause;
     private String firstname;
     private String lastname;
     private String profession;
     private Set investigationMaterials = new HashSet(0);

    public OrderEntry() {
    }

    public OrderEntry(String reference, String type, String cause, String firstname, String lastname, String profession, Set investigationMaterials) {
       this.reference = reference;
       this.type = type;
       this.cause = cause;
       this.firstname = firstname;
       this.lastname = lastname;
       this.profession = profession;
       this.investigationMaterials = investigationMaterials;
    }

    public Integer getOrderid() {
        return this.orderid;
    }

    public void setOrderid(Integer orderid) {
        this.orderid = orderid;
    }
    public String getReference() {
        return this.reference;
    }

    public void setReference(String reference) {
        this.reference = reference;
    }
    public String getType() {
        return this.type;
    }

    public void setType(String type) {
        this.type = type;
    }
    public String getCause() {
        return this.cause;
    }

    public void setCause(String cause) {
        this.cause = cause;
    }
    public String getFirstname() {
        return this.firstname;
    }

    public void setFirstname(String firstname) {
        this.firstname = firstname;
    }
    public String getLastname() {
        return this.lastname;
    }

    public void setLastname(String lastname) {
        this.lastname = lastname;
    }
    public String getProfession() {
        return this.profession;
    }

    public void setProfession(String profession) {
        this.profession = profession;
    }
    public Set getInvestigationMaterials() {
        return this.investigationMaterials;
    }

    public void setInvestigationMaterials(Set investigationMaterials) {
        this.investigationMaterials = investigationMaterials;
    }
}

映射文件

<hibernate-mapping>
    <class name="forensikmysql.entity.OrderEntry" table="order_entry" catalog="forensik_db" optimistic-lock="version">
        <id name="orderid" type="java.lang.Integer">
            <column name="orderid" />
            <generator class="identity" />
        </id>
        <property name="reference" type="string">
            <column name="reference" length="20" />
        </property>
        <property name="type" type="string">
            <column name="type" length="50" />
        </property>
        <property name="cause" type="string">
            <column name="cause" length="50" />
        </property>
        <property name="firstname" type="string">
            <column name="firstname" length="50" />
        </property>
        <property name="lastname" type="string">
            <column name="lastname" length="50" />
        </property>
        <property name="profession" type="string">
            <column name="profession" length="50" />
        </property>
        <set name="investigationMaterials" table="investigation_material" inverse="true" lazy="true" fetch="select">
            <key>
                <column name="orderid" />
            </key>
            <one-to-many class="forensikmysql.entity.InvestigationMaterial" />
        </set>
    </class>
</hibernate-mapping>

也许有人可以告诉我一种使用表格和文本字段在GUI中显示数据的方法。

0 个答案:

没有答案