Avatar billede fredand Forsker
03. september 2010 - 22:12 Der er 1 løsning

How to tell JPA to queue threads?

Hello guys!

We get a ORA-00054 from Oracle when we stress our application.
The exception looks like:
java.sql.SQLException: ORA-00054: resource busy and acquire with NOWAIT specified

The code that cause this is this JPA-code:

MyObject myObject =(MyObject)em.find(MyObject.class, id);
em.lock(myObject, LockModeType.WRITE);

What we want is that when several threads access this code they should wait in a nice line until they can set there own lock.
Now it looks like that next thread accessing this code it just get a exception back from oracle.

If I'm not wrong the JPA-code above do some SQL like:
select * from myobject where id = x for update nowait

We of course would like it to do something like:
select * from myobject where id = x for update wait

But how do we send the "wait"-param?

Right now I can not give information of what version of JPA we use. I just know that we use EJB 3.0 with JBoss 5.

Bets regrads
Fredrik
Avatar billede fredand Forsker
18. oktober 2010 - 08:33 #1
Hello!

It turned out that our version if JPA did not support this.
We had to go to our hibernate (impl of JPA) and do:

    org.hibernate.Session session = (org.hibernate.Session) em.getDelegate();
      OurObject object = (OurObject )session.get(OurObject.class, primaryKey, org.hibernate.LockMode.UPGRADE);
     
      // Now it is possible to do our operation
      String counter = .. bla bla(object);
      em.merge(object );
     
      return counter;

Best regards
Fredrik
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Kurser inden for grundlæggende programmering

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester