首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2EE开发 >

hibernate有关问题求解

2012-08-16 
hibernate问题求解jsp中有这样的代码:Java codetd width73 height30 bgcolorF9F9F9用户名/td

hibernate问题求解
jsp中有这样的代码:

Java code
<td width="73" height="30" bgcolor="F9F9F9">用户名</td>          <td width="288" height="30" align="left" bgcolor="#FFFFFF"><s:textfield name="account"/><s:fielderror><s:param [color=#FF0000]value="%{'account'}"[/color]/></s:fielderror></td>


点击提交相应的action方法:
Java code
public String addUserInfo() {    objectDao = new ObjectDao<UserInfo>();    boolean flag = objectDao.saveT(userInfo);         ……    return "operationUser";}

Java code
[code=Java]public boolean saveT(T t) {        Session session = sessionFactory.openSession();//开启Session        try {            tx = session.beginTransaction();//开启事务            session.save(t);//执行数据添加操作            tx.commit();//事务提交        } catch (Exception e) {            e.printStackTrace();            return false;        } finally {            session.close();//关闭Session        }        return true;    }

映射表的相关片段:
<property name="account" type="string">
  <column name="account" not-null="true" />
  </property>[/code]

数据是怎么保存到数据表的,没有获取表达的代码,数据也能插入到表里?是hibernate的内部机制完成的吗?

[解决办法]
你调用了save他就知道你要insert,他通过配置文件反射机制得到你的类和表,然后组装成SQL执行。
[解决办法]
反射机制是可以得到包括你的private值的。

热点排行