How to use or manage UserTransaction API to persist jcr data in AEM nodes through OsGi service. | Community
Skip to main content
Level 2
January 4, 2018
Solved

How to use or manage UserTransaction API to persist jcr data in AEM nodes through OsGi service.

  • January 4, 2018
  • 5 replies
  • 3054 views

Hi people,

I am trying to initiate Javax.transaction on jcr resource and storing content on AEM localhost:4502, I just could not get the way out to initialize UserTransaction to jcr repository, Not sure whats the JNDI lookup context jn that case, because jcr repository is not the data source.i just want transactions to rollback/commit dependending on sucess/failure rates. Doea anyone have idea??

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by joerghoh

when you deal with JCR solely, you don't need JTA.

5 replies

smacdonald2008
Level 10
January 5, 2018

Not a lot of transaction inforomation online about JCR and transactions. See this doc that may help -- JCR 2.0: 21 Transactions (Content Repository for Java Technology API v2.0)

joerghoh
Adobe Employee
Adobe Employee
January 5, 2018

Why would you use javax.transaction API? The JCR session API already offers transaction support. Of course you cannot span a transaction multiple datasources (for example a SQL database which should be updated in the same transaction as JCR).

It's that what you want to do?

Jörg

nupur_kAuthor
Level 2
January 6, 2018

No, I dont want to update JCR and data source simultaneously, I want to save all the JCR transactions once in the end, by utx.commit()  if there are no failure rates, and utx.rollback() in case of single failure. So I think if anyway we can make use of JTA transactions, to store transient data and submit and rollback as needed

repository = JcrUtils.getRepository("http://localhost:4502/crx/server");

   //Create a Session

javax.jcr.Session session = repository.login( new SimpleCredentials("admin", "admin".toCharArray()));

  

   Object sling;

//final SlingRepository repository = sling.getService(SlingRepository.class);

//   Session session = repository.loginAdministrative(null);

   Node root = session.getRootNode();

   Hashtable env = new Hashtable();

   Context ctx = null;

   env.put(Context.PROVIDER_URL, "http://localhost:4502/crx/server");

   env.put(Context.INITIAL_CONTEXT_FACTORY,"jcr/repository");

   ctx = new InitialContext(env);

  

  

   UserTransaction utx = (UserTransaction)

     ctx.lookup("javax.transaction.UserTransaction");

nupur_kAuthor
Level 2
January 6, 2018

yes agree.. I came across the link and I m facing issues with setting context to UserTransaction Object.

joerghoh
Adobe Employee
joerghohAdobe EmployeeAccepted solution
Adobe Employee
January 6, 2018

when you deal with JCR solely, you don't need JTA.