Friday, 15 April 2011

nhibernate - How should I be configuring spring and hibernate so that my Integration Tests replicate properly the behaviour of the Web application? -


We have a web application based on NSpring 1.2 and NHibernate 2 and use the hibernate template. The web app is configured to use OpenSessionInViewModule .

In our integration tests, however, the hibernate session has been marked as InitDeferredClose and for the most part it works fine for some of our service functions which are available for web applications Well done in the context of, but if unsuccessful, call from the Test Horn.

For example: I have a function that creates and updates many objects within a transaction, the function is marked with the transaction attribute, but the test fails with the message:

/ P>

  Invalid attempt to associate a collection with two open sessions  

Since the web application called, the transaction is successfully completed

How do I make spring configuration? Should be in hibernation and so that my integrity test repeats the efficiency of the web application properly

A session-scope example should be made in the up section and then it should be terminated (endow) at the end. This should duplicate the OSIV model very well. Here's a simple sample:

  using the system; Using NHibernate; Using NUnit.Fraamework; Using Spring.Data.NHibernate.Support; [TESTIFECTIONS] Public Class OCVICindOfTest {Private session-scope area; // Get local sessionfireers from anywhere // watch spring Testing Illegal and auto-injection personal eraistation fundamentals; [Set Up] Public Zero Onset () {Scope = New Session Squad (SessionFire, Empty, Truth, Flushmode, Anytime, Truth); } Public Zero TestSomething () {// Just a Dummy Demo Console WrightLine (sessionFactory.GetCurrentSession (. Statistics.AntityCount); } [Tyrund] Public Zero Tyrundown () {if (Scope! = Null) {scope.Dispose (); }}}  

This sample expects that the localizationfishing object of the spring has set ExposeTransactionAwareSessionFactory to True


No comments:

Post a Comment