I am working with JBOSS 4.0.4GA and Hibernate 3.1.3
I am attempting to manipulate a record in Oracle. For some reason, I am having to manually flush the session to get the changes to show up in the database. From the documentation I have read, I should not have to flush the session as long as I call commit() on the transaction.
I am using Hibernate as a MBean Service in JBOSS with har deployment.
Here is my code
public void delete(int acctId){ Session session = null; Transaction tx = null; try { session = ServiceLocator.getHibernateSession(HIBERNATE_SESSION_FACTORY); tx = session.beginTransaction(); AccountBean acctBean = (AccountBean) session.get(AccountBean.class,acctId); //For debugging if (acctBean == null) { System.out.println("AccountBean = Null"); } else { System.out.println("AccountDelete"); System.out.println("-AcctID = " + acctBean.getAcctId()); System.out.println("-AcctNum = " + acctBean.getAcctNum()); System.out.println("-AcctName = " + acctBean.getAcctName()); } session.delete(acctBean); tx.commit(); } catch (Exception e) { try { tx.rollback(); } catch (Exception e2) { System.out.println(e2); } System.out.println(e); } finally { try { if (session != null) { //Why do I need to call flush here? session.flush(); session.close(); } } catch (Exception e) { System.out.println(e); } }
What is your problem?