-->
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.  [ 4 posts ] 
Author Message
 Post subject: EntityManager Flush with Oracle
PostPosted: Thu Mar 05, 2009 11:33 am 
Newbie

Joined: Mon Nov 14, 2005 5:17 am
Posts: 13
Hey,

I use Hibernate (with EJB3 annotations)
I have a method that is executed for a long time and execute sort of an Action (an entity)

I would like to manage status of the action, so before execution, I change the Action.status to 'RUNNING', then I invoke em.flush() in order to commit the status first before the long running method execution phase.


So the code looks like:

Code:
Action a = em.find(Action.class,5);
a.setStatus("RUNNING");
em.flush();

a.invoke(); //long running...



I can see the query in the log file after em.flush is invoked but the change does not happen on the DB.


With Mysql, it works fine, the problem only happen with Oracle, (maybe there's a need somewhere to do a commit?)


Any ideas?


Thanks in advanced,


Asaf.
[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 05, 2009 11:46 am 
Expert
Expert

Joined: Thu Jan 08, 2009 6:16 am
Posts: 661
Location: Germany
I think you are right, you have to commit your transaction.
I don't know what kind of Transaction API you use (JTA?) but you could try to call em.getTransaction().begin() before and em.getTransaction().commit() after your statement.

_________________
-----------------
Need advanced help? http://www.viada.eu


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 05, 2009 12:16 pm 
Newbie

Joined: Mon Nov 14, 2005 5:17 am
Posts: 13
Hey,
Thanks for answering,

I wonder why the behavior is different between the two DB types (Mysql/Oracle) any idea?


Yes, I am using JTA, I'm not too famliar with the behavior, but is it possible to start an inner transaction inside current one that JTA created and then commit the inner one only?, then return back to the original transaction?

I don't want to disturb the standard behavior as the invocations that occur after the status update are very long and complicated, thus I don't want to mange the transaction myself, only for the update.


Thanks,

Asaf.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 05, 2009 2:52 pm 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
Quote:
I wonder why the behavior is different between the two DB types (Mysql/Oracle) any idea?


What kind of table type are you using with MySQL? I would guess that you are using MyISAM tables (the default for MySQL). This table type doesn't support transactions and it doesn't matter if you commit() or not. Instead, you should use the InnoDb table type which support transactions. You should also configure Hibernate to use the MySQL5InnoDBDialect.


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