hibernate中用sql addBatch

现在在维护公司前段时间的一个项目,变态的设计 n个表都存有用户表的外键 ,并且是单向的,删除用户无法删除数据,无奈只能写sql了,在hibernate中用了sql的addBatch

<textarea cols="50" rows="15" name="code" class="java">Session session=getSession(); Transaction ts = session.beginTransaction(); Connection conn=session.connection(); Statement st=conn.createStatement(); String sql=&quot;delete from ur where USER_ID in(&quot;+subids+&quot;)&quot;; st.addBatch(sql); sql=&quot;delete from RONG_USERS_ROLEINFO where USERS_ID in(&quot;+subids+&quot;)&quot;; st.addBatch(sql); sql=&quot;delete from RDMP_RELEVANCESYSTEM where USERS in(&quot;+subids+&quot;)&quot;; st.addBatch(sql); sql=&quot;delete from RDMP_RELEVANCESYSTEMPARAMS where USERS in(&quot;+subids+&quot;)&quot;; st.addBatch(sql); sql=&quot;delete from Users where id in (&quot; + subids + &quot;)&quot;; st.addBatch(sql); st.executeBatch(); ts.commit();</textarea>

你可能感兴趣的:(hibernate中用sql addBatch)