Monday, 24 October 2016

javax.jcr.lock.LockException: Precondition Failed

A solution for javax.jcr.lock.LockException

In one of my previous posts I showed how to connect to JCR using a simple
main() method , Java program
This is a simple program and should work fine in most of the cases.
But for some people it might throw a javax.jcr.lock.LockException.


While connecting to the JCR we may use something like below.

 Session session = repository.login(new SimpleCredentials("admin", "admin".toCharArray()));
This statement may sometimes lead to an error in applications like AEM.
To avoid this we need to mention the default environemnt we are logging into.

So we should USE THIS INSTEAD.

Session session = repository.login( new SimpleCredentials("admin", "admin".toCharArray()),"crx.default");

I would be happy to hear back from you. Please leave your suggestions in the comment section below. Cheers!!