JPA - Pessimistic lock

0 respostas
kleins

Galera.

Estou tentando fazer um lock em um (ou mais) registros e estou recebendo a seguinte mensagem :

Internal Exception: java.sql.SQLException: ORA-00054: o recurso está ocupado e é obtido com o NOWAIT especificado Error Code: 54 Call: SELECT ID, IUM, STATUS FROM CODE WHERE (STATUS = ?) FOR UPDATE NOWAIT bind => [OK] Query: ReportQuery(br.org.system4.entity.Code)

Oque eu quero é bloquear um registro quando eu pego ele, pois essa tabela terá muita concorrência....

Estou usando Glassfish, JPA (Toplink) e Oracle.

Será que no pool do glassfish eu tenho que alterar alguma coisa ?

O código que está abaixo.

try {
            //throw new UnsupportedOperationException("Not supported yet.");
            Context ctx = new InitialContext();


            UserTransaction utx = (UserTransaction) ctx.lookup("java:comp/env/UserTransaction");
            utx.begin();
            EntityManager em = (EntityManager) ctx.lookup("java:comp/env/persistence/LogicalName");

            Query q = em.createQuery("SELECT c FROM Code c where c.status='OK'");
            q.setMaxResults(i);
            q.setHint(TopLinkQueryHints.PESSIMISTIC_LOCK, PessimisticLock.LockNoWait);
         
            List lcodes = q.getResultList();
            
            lc = q.getResultList();
            
            utx.commit();
            
            ctx.close();
            
            
        } catch (RollbackException ex) {
            Logger.getLogger(CodeDAOjpa.class.getName()).log(Level.SEVERE, null, ex);
        } catch (HeuristicMixedException ex) {
            Logger.getLogger(CodeDAOjpa.class.getName()).log(Level.SEVERE, null, ex);
        } catch (HeuristicRollbackException ex) {
            Logger.getLogger(CodeDAOjpa.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SecurityException ex) {
            Logger.getLogger(CodeDAOjpa.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IllegalStateException ex) {
            Logger.getLogger(CodeDAOjpa.class.getName()).log(Level.SEVERE, null, ex);
        } catch (NotSupportedException ex) {
            Logger.getLogger(CodeDAOjpa.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SystemException ex) {
            Logger.getLogger(CodeDAOjpa.class.getName()).log(Level.SEVERE, null, ex);
        } catch (NamingException ex) {
            Logger.getLogger(CodeDAOjpa.class.getName()).log(Level.SEVERE, null, ex);
        } catch (Exception e) {
            System.out.println("EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE : "+e.getMessage());
        }

Valeu Galera.

Criado 1 de abril de 2009
Respostas 0
Participantes 1