-->
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.  [ 3 posts ] 
Author Message
 Post subject: Delete not working (on a transient object, I think)
PostPosted: Wed Apr 07, 2004 9:37 am 
Newbie

Joined: Tue Mar 09, 2004 2:44 pm
Posts: 15
Here is the code that is not deleting...

Code:
    private void delete (HibernateExUser theUser) {
        try {
            Session session = HibernateUtil.currentSession();
            session.setFlushMode(FlushMode.AUTO);
            //simply delete the retrieved user if we are deleting
            session.delete(theUser);
            HibernateUtil.closeSession();
        } catch (Throwable e) {e.printStackTrace();}
    }


Note that the session in currentSession() must be built (HibernateUtil.close() called before this method is called). Also, I have a similar method called save() that uses the exact same steps (get a new session, save user, close session) to save a new user, and that works perfectly fine. No flush() required.

This method works fine if I add a session.flush() between delete()/closeSession() calls. That's not a surprise. The default FlushMode for each session HibernateUtil returns is COMMIT. However, my save() method worked perfectly fine without resetting the flushMode of the session as I have in the code above.

In other words, session.save() seems to automatically flush, while session.delete() does not. Is this correct? Note that I am running through evaluating Hibernate and testing how it can be used, not necessarily trying to get this code to work (which would mean adding the session.flush() and be done).

_________________
Thanks,
CJ


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 07, 2004 9:49 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Neither save() nor delete() flushes automatically. However, some inserts must be done before flush time (eg. when you use "identity" or "native" ids).

I'm sure your problem is that you don't flush.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 07, 2004 9:55 am 
Newbie

Joined: Tue Mar 09, 2004 2:44 pm
Posts: 15
It is an identity column in SQL Server, so that would be the explanation, it seems.

_________________
Thanks,
CJ


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

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.