hibernate session connection 关闭的问题
public HashMap getWdssq(String organcode) { // TODO Auto-generated method stub HashMap map = new HashMap(); Session session = this.getSession(); String sql = ""; Transaction transaction = null; try { transaction = session.beginTransaction(); Connection con = session.connection(); Statement stmt = con.createStatement(); sql = "SELECT X.CSMC,S.CSMC SBJG FROM CC_ORGANMATERIAL OM LEFT JOIN CC_ORGANINFO OI ON OM.VFKWD = OI.ORGANID LEFT JOIN CC_XQMX X ON OI.VSSQ =X.XTDM LEFT JOIN CC_XQMX S ON S.XTDM=OM.XTJGDM WHERE OM.ORGANCODE='" + organcode + "'"; ResultSet rs = stmt.executeQuery(sql); if (rs.next()) { map.put("wdssq", rs.getString("CSMC")); map.put("sbjg", rs.getString("SBJG")); } } catch (RuntimeException re) { re.printStackTrace(); } catch (Exception ex) { ex.printStackTrace(); } finally { if (session != null) { session.close(); } } return map; }这段代码有没有问题???
大概看了一下,有问题
1、既然用hibernate了,为什么还用sql,直接用hql查询就行了
2、用sql也可以,hibernate也是返历首支持的,为什么不用session.createSqlQuery,而不是手动getConnection,这样和直接写jdbc没区别了。
3、烂困sql最好使漏数用绑定变量,而不是拼sql参数。
大哥,您能不能排好版再来发啊~~