-->
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.  [ 6 posts ] 
Author Message
 Post subject: HELP!!!! about flush() and commit()
PostPosted: Fri Jun 17, 2005 4:58 am 
Newbie

Joined: Fri Jun 17, 2005 4:08 am
Posts: 4
Version: Hibernate 3.0.5/3.0.4,

I can't save my data into database when only use session.flush(), actually, when I run the programe in DEBUG mode and DEBUG it step by step, I can see that there is one record which has been inserted into my tables, but when DEBUG was terminated, the record I saw before had been deleted as well.(there is no error messages)

CODE 1 -- Without persist data
===========================================================
Session session = HibernateSession.currentSession();
Long generatedId = (Long) session.save(v);
session.flush();
===========================================================

But In another hand, everything goes fine when I use a transatcion to commit().

CODE 2 -- It's Ok now
===========================================================
Session session = HibernateSession.currentSession();
Transaction tx = session.beginTransaction();
Long generatedId = (Long) session.save(v);
session.flush();
tx.commit();
===================================================

So, I don't wanna to begin a transaction in my application, what can i do? I haven't meet these problems in Hibernate 2. Thanks very much.

PS: I run my code without an application server, and my development tool is Websphere Studio Application Developer V5.1

Best Regards,


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 17, 2005 10:32 am 
Regular
Regular

Joined: Thu Apr 21, 2005 9:05 am
Posts: 50
Location: Boston, U.S
What sort of Transaction Management you are following
CMT or BMT??


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 17, 2005 3:29 pm 
Expert
Expert

Joined: Sat Jan 17, 2004 2:57 pm
Posts: 329
Location: In the basement in my underwear
Out of curiosity why wouldn't you want to create a transaction?

In hibernate2 you didn't have access to the currentSession so you could always go back to whatever you were doing before to get around transactions but I still don't think you'd want to. Be prepared for Christian to beat you with the transaction stick ;)


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jun 18, 2005 10:33 am 
Newbie

Joined: Fri Jun 17, 2005 4:08 am
Posts: 4
I want manage my transaction in another way(such as mamagered by Container). so my base DAO shouldn't create any transaction.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jun 18, 2005 10:45 am 
Newbie

Joined: Fri Jun 17, 2005 4:08 am
Posts: 4
the question is that if i use flush() with out create a transaction, there seems nothing happend on my db.

STEPS:

public static void main(String[] args)

{
.....

session.save(obj);
session.flush();
// when i debug my code, i can saw there was a new row inserted into my table
session.close();

.....

}

// but when my appliation(main()) was terminated, the row was deleted. :(


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jun 18, 2005 10:47 am 
Newbie

Joined: Fri Jun 17, 2005 4:08 am
Posts: 4
if my code like this,everything is fine, but i don't wanna create any transaction in my DAO.

public static void main(String[] args)

{
.....

tx = session.beginTransaction();
session.save(obj);
session.flush();
tx.commit();
session.close();

.....

}


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 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.