-
Notifications
You must be signed in to change notification settings - Fork 32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow access the NHibernate SynchronizedStorageSession with the TransactionalSession without having to open it first #1019
Comments
@hugovlc You want to have access to a NHibernate session factory that is used by the transactional session and also the incoming message pipeline? |
Thank you for the reply. I want to have the ISession. What happens is that the session is built when we open a Transaction with the TransactionalSession. Is related to the SynchronizedStorageSession. I think we should have the option to open it without a NServicebus transaction. Basically I changed the NServiceBus.TransactionalSession to have the possibility to open the SynchronizedStorageSession and then changed the NServiceBus.NHibernate NHibernateLocalOutboxTransaction and OutboxPersister to pass the ISession created previously. I did not implemented for sagas or TrsanctionScope. |
@hugovlc Can I summarize it to that you would like to the ability to:
May I ask why you couldn't just create the transactional session immediately? Why is that a bad approach for your application? |
Is bad practice in general having the data in a Transactional mode if I only want to query data. So having access SyncronizedStorageSession (with another method in the ITransactionSession interface) , and then when I open a OutboxTransaction, that session could be passed if SyncronizedStorageSession is already opened. if not use the current default behavior. |
@hugovlc what kind of queries on what data would you like to make? I assume this is data which not part of a saga context? |
@hugovlc Side note: I assume you are using connection pooling and when you do you always need to specify a transaction mode. Even when not using transactions you should for example do:
Not doing so can result in strange transaction isolation issues as the isolation level is never reset when a connection is returned into the connection pool as its assumed that a new consumer will always set its required isolation level. |
I understand that. The issue is that in any method i call, for example a rest api call, i have ro open the nservicebus transaction and then change all my calls that does not uses nservicebus im order to close the transaction. Again i am using DI and cannot cherry pick a different ISession for each case. The ISession should be available as a extra option in the TransactionalSession. I already forked both the Nhibernate and TransactionalSession repos and the change was very easy. But i don't wanna maintenant the code. I think this is logical. |
@hugovlc I'm not 100% sure what you are asking for. I thought its only about resolving an You state that you want to have access to the using (ITransaction transaction = session.BeginTransaction(IsolationLevel.ReadCommitted))
{
// Do your queries here
} From what I understand from you is that you would then later pass this session into the transaction session As sessions are cheap to create I think it would be ok if the transactional session creates its own session but I think I'm misunderstanding something from your responses.
As you state you already made some changes could you please share your changes including maybe a small demo project? If these are good changes we can consider merging them in a future maintenance release or use them as inspiration for a similar API change. |
Hi. Sorry to say you are wrong. We don't need to create a Transaction every time we query something. So let's say I Have a controller and I have a Service Layer to do something. I have a UnitOfWork to handle the DB operations (Transactions, interceptions, etc) The ISession needs to be accessible, So in my service registration I have to register an instance, but first I need to resolve the ITransactionSession service, then open a transaction. So in EVERY METHOD that I do not commit anything I need to refactor it.. Is just not doable. |
@hugovlc Actually, I'm not wrong. That is the only way to state your required isolation level and not accidentally query using the wrong previous connection cached isolation level. So unless you are not using connection pooling as mentioned earlier you really need to do this.
Only when ALL database operations are based on the same isolation level (for example, ReadCommitted) you don't need this. |
👍🏼 |
I think you miss understood me. Also btw we use Oracle as business DB with SqlServer Transport. |
Describe the suggested improvement
Currently with the TransactionalSession we can open a transaction and then have access to the SyncronizedStorageSession where we can get the ISession.
In a scenario with dependency Injection where we might need it or not, in order to have access to the ISession we currently need to open the transaction. We should be allowed to have access to the SyncronizedStorageSession even if we don't open a TransactionSession.
I understand this was implemented like this, I guess the feature wants to prevent NHibernate transactions to be created outside of the scope of the TransactionalSession context, but this should be the responsibility of the developer.
Don´t know if this should be created here or in the TransactionalSession repository.
Additional Context
No response
The text was updated successfully, but these errors were encountered: