-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Having to manually flush the session?
PostPosted: Fri Jul 28, 2006 12:13 pm 
Beginner
Beginner

Joined: Fri Jul 28, 2006 12:01 pm
Posts: 21
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
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);
            }
        }   


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.