当前位置: 代码迷 >> J2EE >> hibernate有关问题求解
  详细解决方案

hibernate有关问题求解

热度:58   发布时间:2016-04-22 01:04:39.0
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值的。
  相关解决方案