multi-tenant / grails-multi-tenant-single-db

Multi Tenant implementation for single database environments - Use grails-filtering and grails-hibernate-hijacker

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Is new transaction necessary in MultiTenantService#doWithTenantId()?

nobeans opened this issue · comments

from javadoc comment

    /**
     * Execute some code in the 'namespace' of the given tenant id.
     * The code will be executed in a new transaction with a new session
     * to avoid other tenants entities laying in the first level cache to leak in.
     */

If the problem is caused by the first level cache, I think it can be fixed by using only new session or a current session after calling clear() instead.
a forced individual transaction is inconvenient for me. I want to control a transaction by myself out of the service.

Why don't you make a copy of that method without the transaction handling and see how it works out for you? It's been a while, but I remember running into some strange issues with that piece of code.

sure. I can do it and actually did it. But I think in almost case you must want to control a transaction out of the service. So I want a way to control it by default if possible.

but I remember running into some strange issues with that piece of code.

it's when using only new session without new transaction?

What problem have you met before you committed the following commit?

commit 0874bfe641a8c330bdac97afca7d0fc4ff4aa053
Author: Kim A. Betti <kim.betti@gmail.com>
Date:   Sat Feb 19 18:41:11 2011 +0100

    Made doWithTentant run within a new transaction to avoid the previous tenant-id leaking in

If any problem may occurs when using my service which doesn't start both new session and new transaction, I can't use it.

You probably have to investigate it. I never really got to the bottom of that problem and it's so long ago that I don't remember the details of it.

ok. I think that new transaction is unnecessary. so I try to use my service which uses only new session. If something happen, I'll report newly. thanks.