nhibernate - Castle Automatic Transaction Management Facility persist issues -


regarding castle automatic transaction management facility; i'm having difficulties getting operations save database without flushing session.

i'm using following components * nhibernate.dll v3.1.0.4000 * castle.core.dll v2.5.2.0 * castle.windsor.dll v2.5.3.0 * castle.facilities.nhibernateintegration.dll v1.1.0.0 * castle.services.transaction.dll v2.5.0.0 * castle.facilities.autotx.dll v2.5.1.0

i have followed castle documentation closely , have not been able resolve issue.

my (web-)application follows mvp pattern. key parts of (transactional) presenter-service shown below:

<transactional()> _ public class campuseditpresenter     inherits basepresenter(of icampuseditview)      public sub new(byval view icampuseditview)         mybase.new(view)     end sub      ...      <transaction(transactionmode.requires)> _     public overridable sub save() implements icampuseditpresenter.save          ' simplified         using session isession = _sessionmanager.opensession()              dim campus new campus()              campus.code = _view.code             campus.shortdescription = _view.shortdescription             campus.longdescription = _view.longdescription             campus.startdate = _view.startdate             campus.enddate = _view.enddate              session.save(campus)          end using      end sub  end class 

this presenter-service registered in installer:

container.register( _     component.for(of campuseditpresenter) _     .interceptors(of debuglogginginterceptor) _     .lifestyle.transient) 

and resolved view (in base):

public class basepage(of tpresenter)     inherits page      protected _presenter tpresenter      ...      protected sub page_init(byval sender object, byval e eventargs) handles me.init         _presenter = _container.resolve(of tpresenter)(new {key .view = me})     end sub      ...  end class  public class campusedit inherits basepage(of campuseditpresenter)     implements icampuseditview      ...      protected sub btnsave_click(byval sender object, byval e eventargs) handles btnsave.click         _presenter.save()     end sub      ...  end class 

i have registered nhibernate , transaction facilities in xml configuration file follows:

<facility id="transaction" type="castle.facilities.autotx.transactionfacility, castle.facilities.autotx" /> <facility id="nhibernate" type="castle.facilities.nhibernateintegration.nhibernatefacility, castle.facilities.nhibernateintegration" isweb="true" configurationbuilder="[removed].autoconfigurationbuilder, [removed]">     <factory id="nhibernate.factory">     <settings>             <item key="connection.driver_class">nhibernate.driver.oracleclientdriver, nhibernate</item>       <item key="connection.connection_string">[removed]</item>       <item key="show_sql">false</item>       <item key="dialect">nhibernate.dialect.oracle10gdialect, nhibernate</item>       <item key="query.substitutions">true 1, false 0, yes 'y', no 'n'</item>       <item key="proxyfactory.factory_class">nhibernate.bytecode.castle.proxyfactoryfactory, nhibernate.bytecode.castle</item>       <item key="current_session_context_class">web</item>       <item key="hbm2ddl.keywords">auto-quote</item>         </settings>     </factory> </facility> 

and have registered sessionwebmodule http module in web.config:

<httpmodules>     <add name="nhibernatesessionwebmodule" type="castle.facilities.nhibernateintegration.components.web.sessionwebmodule, castle.facilities.nhibernateintegration"/>     ... </httpmodules> 

any ideas why may not working?

i can working when a) instansiate own transactions isession instance , maually commit these transactions, or if b) use automatic transaction management aop-mechanism , manuall flush session instance (though shouldn't have manually this).

i have thought sessionwebmodule ihttpmodule (which follows open-session-per-request pattern) cause entities persisted, doesnt seem happening...

so worked out transactioninterceptor not getting registerd on components.

after downloading castle.facilities.automatictransactionmanagement source github , stepping through, found issue , managed resolve it.

basically transactionfacility adds contributor, transactioncomponentinspector, componentmodelbuilder, allows additional configuration contribution whilst building component. in case of transactioncomponentinspector, looks "transactional" class attribute on component , if exists register transactioninterceptor on component. however, components never getting contributed transactioncomponentinspector.

to configure/register components on container, use installers. configure container using xml, references these installers facilities (e.g. nhibernate-integration/logging etc.). anyways, believe may have been kind of ordering issue whereby components might have been getting registered before transaction facility. such components registered before transactionfacility not getting contributed-to transactioncomponentinspector , therefore not getting transactioninterceptor registered on component. once realised manually configured container (with correct order of things) , seemed work!!!

now i've got try , work out how in xml configuration. if can't, guess i'll dump , go fluent configuration of container (e.g. in global httpapplication).

[edit] see below:

_container = new windsorcontainer() ' transactionfacility must registered before components. _container.addfacility(of transactionfacility)() _container.install(configuration.fromxmlfile("configs\services.xml")) 

Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -