日期:2014-05-17 浏览次数:20650 次
<hibernate-mapping>
<class name="orm.Userinfo" table="Userinfo" schema="dbo" catalog="woniu">
<id name="id" type="java.lang.Integer">
<column name="id" />
<generator class="native" />
</id>
<property name="username" type="java.lang.String">
<column name="username" length="50" not-null="true" />
</property>
<property name="password" type="java.lang.String">
<column name="password" length="50" not-null="true" />
</property>
<property name="age" type="java.lang.Integer">
<column name="age" />
</property>
</class>
</hibernate-mapping>
package controller;
import orm.Userinfo;
import orm.UserinfoDAO;
public class Insert {
public String execute(){
Userinfo userinfo = new Userinfo();
userinfo.setUsername("woniu");
userinfo.setPassword("000123");
userinfo.setAge(10);
UserinfoDAO userinfoDAO = new UserinfoDAO();
userinfoDAO.getSession().beginTransaction();
userinfoDAO.attachDirty(userinfo);
userinfoDAO.getSession().getTransaction().commit();
userinfoDAO.getSession().close();
return "";
}
}