Spring for .NET Community Forums    

Go Back   Spring for .NET Community Forums > General > Data Access

Reply
 
Thread Tools Display Modes
  #1  
Old 03-12-2008, 01:22 AM
turqoise turqoise is offline
Junior Member
New User
 
Join Date: Mar 2008
Posts: 3
Default Declarative Transaction Configuration

Hi, I can't seem to get declarative transactions working for my setup.

I'm working on an ASP.NET 2.0 application with MSSQL2005 for the db.

The following is the configuration for my adotemplate, transaction manager etc

Code:
  <!-- Production Data Access Objects -->
  <db:provider id="dbProvider"
                 provider="SqlServer-1.1"
                 connectionString="Server=${db.server};Integrated Security=no;User ID=${db.user};PWD=${db.password};initial catalog=${db.schema};"/>

  <object id="adoTemplate" type="Spring.Data.Core.AdoTemplate, Spring.Data">
    <property name="DbProvider" ref="dbProvider"/>
  </object>

  <!-- Transaction Manager if using a single database -->
  <object id="transactionManager"
          type="Spring.Data.Core.AdoPlatformTransactionManager, Spring.Data">
    <property name="DbProvider" ref="dbProvider"/>
  </object>

  <tx:attribute-driven transaction-manager="transactionManager"/>
When I have not declared transaction attributes in my biz class, the application works fine. However once I have declared a method in biz class to be transactional, the daos all end up NULL.

The following code segment is how i declared a method to be transactional. Once [Transaction()] is in, my _codeTableDao ends up NULL.

Code:
        [Transaction()]
        public int InsertCodeTable(CodeTableInfo codeTableInfo)
        {
            _codeTableDao.UpdateCodeTableSequence(codeTableInfo.CodeTableTypeCode, codeTableInfo.ParentID, codeTableInfo.Sequence - 1);

            int codeTableID = _codeTableDao.InsertCodeTable(codeTableInfo);
Any ideas? What could I be missing?
Reply With Quote
  #2  
Old 03-12-2008, 07:13 PM
logicalmind logicalmind is offline
Junior Member
New User
 
Join Date: Mar 2008
Posts: 2
Default

Try this:

Code:
<object id="AdoTemplate" type="Spring.Data.Generic.AdoTemplate, Spring.Data">
    <property name="DbProvider" ref="DbProvider"/>
    <property name="DataReaderWrapperType" value="Spring.Data.Support.NullMappingDataReader, Spring.Data"/>
</object>
Reply With Quote
  #3  
Old 03-13-2008, 02:26 AM
turqoise turqoise is offline
Junior Member
New User
 
Join Date: Mar 2008
Posts: 3
Default

Does that mean that I'll have to convert my whole application to using Generics before I can use declarative transactions in .NET 2.0?
Reply With Quote
  #4  
Old 03-13-2008, 03:28 AM
turqoise turqoise is offline
Junior Member
New User
 
Join Date: Mar 2008
Posts: 3
Default

I've managed to figure out the issue.

I did not create interfaces for my Business classes. Didn't think that this would be a problem as I remember that for Java, I don't need my biz classes to have interfaces.
Reply With Quote
  #5  
Old 03-13-2008, 06:53 AM
Erich Eichinger Erich Eichinger is offline
Senior Member
Spring User
 
Join Date: Jan 2006
Location: Oslo, Norway
Posts: 1,337
Default

Hi,

this turns out as the most often reason for AOP not working. Unfortunately in .NET methods are not virtual by default and thus cannot be overridden unless they are marked virtual or are part of an interface.

-Erich
Reply With Quote
  #6  
Old 03-20-2008, 03:04 AM
swalters swalters is offline
Member
Spring User
 
Join Date: May 2006
Posts: 33
Default

Good timing on this post. I ran into this today and I should know better, but it still bit me.

Erich, is there anyway for Spring to raise an error when it tries to proxy an object that doesn't have an interface? I'm assuming it's not easy or it would have been done already . NHibernate will not allow the mapping of an object if the public properties are not marked virtual. Is there something similar that could be done with Spring?

-Shane
Reply With Quote
  #7  
Old 03-20-2008, 07:10 AM
Erich Eichinger Erich Eichinger is offline
Senior Member
Spring User
 
Join Date: Jan 2006
Location: Oslo, Norway
Posts: 1,337
Default

Hi,

it isn't possible to make this the default behaviour. But I'm thinking about introducing some "strict" mode to make ProxyFactoryObject throw an exception in the case, that an object doesn't implement an interface.

Are there any other ideas/suggestions out there?

-Erich
Reply With Quote
  #8  
Old 03-22-2008, 05:57 AM
dlotts dlotts is offline
Junior Member
New User
 
Join Date: Aug 2007
Location: Cadott, WI
Posts: 10
Smile Suggestion

I think the default behavior should be to log an informational message when the proxy is created and the class (or generated proxy) does not implement an interface other than the standard interfaces:
Spring.Aop.Framework.IAdvised, Spring.Aop.Framework.IAopProxy, and System.Runtime.Serialization.ISerializable

If these are the only three interfaces implemented, its not likely that the proxy will be useful in most cases.

In my case (See the thread) a simple message would have helped me identify the problem immediately. I think the message is all that is necessary for most users. (assuming logging is correctly configured)

The strict setting could cause spring to throw an exception rather than log the message.
Reply With Quote
  #9  
Old 03-25-2008, 04:08 PM
swalters swalters is offline
Member
Spring User
 
Join Date: May 2006
Posts: 33
Default

+1 on DLotts suggestion, except please log it as a WARN on the default so it will stand out better.

-shane
Reply With Quote
  #10  
Old 03-25-2008, 06:27 PM
steinard steinard is offline
Senior Member
Spring User
 
Join Date: Oct 2006
Location: Bergen, Norway
Posts: 357
Default

I agree, sounds sensible.


Cheers,
Steinar.
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 12:09 AM.


Contegix provides first-class managed hosting and partial sponsorship of these forums.

Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.