[keycloak-user] Opening Transactions

Stian Thorgersen stian at redhat.com
Fri Sep 19 03:53:09 EDT 2014


Multiple transactions work as long as they don't run in parallel. We have several tests that do this.

----- Original Message -----
> From: "Marek Posolda" <mposolda at redhat.com>
> To: "Rodrigo Sasaki" <rodrigopsasaki at gmail.com>, keycloak-user at lists.jboss.org
> Sent: Friday, 19 September, 2014 9:47:14 AM
> Subject: Re: [keycloak-user] Opening Transactions
> 
> Hello,
> 
> atm we don't support multiple transactions for the same session. If we would
> ever support it, we will need to traverse the "afterCompletion" list in
> DefaultKeycloakTransactionManager.begin (and also similarly in
> DefaultKeycloakTransactionManager.isRollbackOnly() ). Maybe you can create
> JIRA and we can take a look later? Another thing is that all enlisted
> transactions would also need to support multiple transactions per session
> (for example in case of JPA it is multiple transactions per single
> EntityManager, which JPA supports, but there might be some performance
> issues with it)
> 
> Note that until than, you can use pattern where each transaction will run in
> it's own KeycloakSession. So defacto multiple KeycloakSession per request.
> If you already have any KeycloakSession you can retrieve
> KeycloakSessionFactory with:
> KeycloakSessionFactory factory = session.getKeycloakSessionFactory();
> 
> And then you can use for example: KeycloakModelUtils.runJobInTransaction to
> use separate KeycloakSession and transaction for your task. Does it work for
> your usecase?
> 
> Marek
> 
> On 19.9.2014 00:13, Rodrigo Sasaki wrote:
> 
> 
> 
> Hello,
> 
> I have created some custom endpoints for my project, and in one of them I
> need to use multiple transactions on a single request. I ran into some
> issues, even though I call
> 
> session.getTransaction().begin()
> 
> It didn't work correctly saying that I didn't have an opened transaction. I
> look a little deeper and saw that there are 2 lists of transactions inside
> org.keycloak.services.DefaultKeycloakTransactionManager.
> 
> One is called transactions and the other is afterCompletion
> 
> when commit() is called, both lists are traversed committing every single
> transaction in them, but when begin() is called, only the transactions list
> is traversed, and the one I needed was inside afterCompletion , which
> remained closed.
> 
> Is this supposed to be this way? I'm not sure what these lists do, but maybe
> the other one should be opened too.
> 
> Is there a problem on opening the transactions on afterCompletion list as
> well?
> 
> Thanks!
> 
> --
> Rodrigo Sasaki
> 
> 
> _______________________________________________
> keycloak-user mailing list keycloak-user at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/keycloak-user
> 
> 
> _______________________________________________
> keycloak-user mailing list
> keycloak-user at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/keycloak-user


More information about the keycloak-user mailing list