Hibernate Books

All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Table locks during function is running.
PostPosted: Fri Apr 13, 2012 9:01 am 
Newbie

Joined: Fri Apr 13, 2012 8:57 am
Posts: 2
Hi i am using

Seam 2.2 , Jboss 6.1, hibernate 3.5.6 and MSQL Server 2008


and have a function like this.


public void deliverFile() {
Code:
   EntityManager jobbEntityManager = (EntityManager)Component.getInstance("jobbEntityManager");

      JobbStatusInterface jobbStatus = new JobbStatus();
      jobbStatus.setStatus(PluginStatus.INITIATED);
      jobbEntityManager.persist(jobbStatus);


                /**

                     Code here to save a file that takes a minutes
                 **/





      jobbStatus.setStatus(PluginStatus.DONE);
      jobbEntityManager.flush();





        }
        public void checkJobb(){
      EntityManager jobbEntityManager =  (EntityManager)Component.getInstance("jobbEntityManager");

         jobbEntityManager.createQuery("from JobbStatus", JobbStatus.class).getResultList();


        }



i have a poll on checkJobb every 10 seconds so if the deliveryFile() function is executed.

the checkJobb queues upp and stops at the query, so when deliveryFile() functions finishes it finish all 6 checkJobbs() at once.

Even if i select from the database directly it is locked and finishes it's query after deliveryFile() is done.


Is there anyway to solove this so i can do my checkJobb() while deliveryFile is executing?


Top
 Profile  
 
 Post subject: Re: Table locks during function is running.
PostPosted: Fri Apr 13, 2012 9:39 am 
Expert
Expert

Joined: Tue Jun 16, 2009 3:36 am
Posts: 988
Hi,

you probably have to use READ_COMMITTED_SNAPSHOT instead to normal READ_COMMITTED isolation.
In this way your query don't will get locked until the other session commits its changes on that table.


Top
 Profile  
 
 Post subject: Re: Table locks during function is running.
PostPosted: Fri Apr 13, 2012 1:02 pm 
Newbie

Joined: Fri Apr 13, 2012 8:57 am
Posts: 2
Thanks, worked like a charm.

Are there any downsides with using this setting?


Top
 Profile  
 
 Post subject: Re: Table locks during function is running.
PostPosted: Mon Apr 16, 2012 2:36 am 
Expert
Expert

Joined: Tue Jun 16, 2009 3:36 am
Posts: 988
I suggest you to read some documentation about READ_COMMITTED_SNAPSHOT on http://http://msdn.microsoft.com and in the internet.
Usually the downsides of this setting are negligible.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 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.