How o force 'select for update' with jpa hibernate

I have a jpa repository where I need to force a select for update query,

this is my code:

 

public DocumentTransaction findOneNonCompleted(String uuid, boolean lockForUpdate)
    {
        TypedQuery query = getEntityManager().createQuery("SELECT t FROM DocumentTransaction t WHERE t.uuid = ?1 AND t.docStatus = TransactionStatus.PROCESSING", DocumentTransaction.class);
        if (lockForUpdate)
        {
            query.setLockMode(LockModeType.PESSIMISTIC_WRITE);
            query.setHint("javax.persistence.lock.timeout",30000);
        }

        query.setParameter(1,uuid);
        List<DocumentTransaction> result = query.getResultList();
        ....
    }

 

 

I didn't get to debug it completely, the code works but I'm not sure about locking because I keep seeing this log message from hibernate:

[timeoutScheduler-2] INFO  hibernate.ejb.AbstractQueryImpl - Ignoring unrecognized query hint [javax.persistence.lock.timeout]

 

which makes me think that hibernate is ignoring my hint,

any ideas someone?

 

Thanks.

 



Share this article: