PDA

View Full Version : Transaction Problem



efren.casillas
11-29-2007, 11:25 PM
Hi
I am facing this error, I had a problem with lazy loading and I implemented in the web.config the openSessionView but when i returned to run my application again, this error ocurred when i tried to save or update.

Could you help me please,


Write operations are not allowed in read-only mode (FlushMode.NEVER) - turn your Session into FlushMode.AUTO or remove 'readOnly' marker from transaction definition

i have this to handling the transactions in the web.config:

<object id="hibernateTransactionManager"
type="Spring.Data.NHibernate.HibernateTransactionManager , Spring.Data.NHibernate">
<property name="DbProvider" ref="DbProvider"/>
<property name="SessionFactory" ref="MySessionFactory"/>
</object>


<object id="genericDaoTransProxy"
type="Spring.Transaction.Interceptor.TransactionProxyFac toryObject, Spring.Data">

<property name="PlatformTransactionManager" ref="hibernateTransactionManager"/>
<property name="Target">
<object type="RheemAdmin.Spring.GenericDao, RheemAdmin">
<property name="SessionFactory" ref="MySessionFactory"/>
</object>
</property>
<property name="TransactionAttributes">
<name-values>
<add key="Save*" value="PROPAGATION_REQUIRES_NEW"/>
<add key="SaveO*" value="PROPAGATION_REQUIRES_NEW"/>
<add key="Delete*" value="PROPAGATION_REQUIRED"/>
<add key="Update*" value="PROPAGATION_REQUIRED"/>
<add key="Query*" value="PROPAGATION_REQUIRED"/>
</name-values>
</property>
</object>

Erich Eichinger
12-03-2007, 09:22 PM
hi,

What's your exact stacktrace?

It seems that your transaction configuration doesn't intercept your methods. Are you using interfaces? Are your Save* etc. methods virtual? This is a requirement to allow proxies to intercept the calls to those methods.

-Erich

efren.casillas
12-07-2007, 05:13 PM
Hi Erich,
Thank you for your response, what do you mean with virtual methods? are you saying that i have to declare all my methods in my dao or my pojos, virtual?

this is the stackstace:



2007-12-07 10:09:23,836 [7752] DEBUG Spring.Context.Support.WebSupportModule [(null)] - Set default resource protocol to 'web' and installed HttpContext-aware HybridContextStorage
2007-12-07 10:09:23,882 [7752] DEBUG Spring.Context.Support.WebSupportModule [(null)] - Initializing Application instance
2007-12-07 10:09:23,961 [7752] DEBUG Spring.Context.Support.WebApplicationContext [(null)] - looking up web context 'spring.root' in WebContextCache
2007-12-07 10:09:23,961 [7752] DEBUG Spring.Context.Support.WebApplicationContext [(null)] - looking up web context 'spring.root' in ContextRegistry
2007-12-07 10:09:23,961 [7752] DEBUG Spring.Context.Support.WebApplicationContext [(null)] - web context for vpath 'spring.root' not found. Force creation using filepath '/BISWeb/dummy.context'
2007-12-07 10:09:23,961 [7752] DEBUG Spring.Context.Support.ContextHandler [(null)] - creating context '/BISWeb'
2007-12-07 10:09:23,976 [7752] DEBUG Spring.Objects.Factory.Support.WebObjectFactory [(null)] - hooking up event handlers
2007-12-07 10:09:24,226 [7752] DEBUG Spring.Objects.Factory.Support.AbstractObjectDefin itionReader [(null)] - Loading XML object definitions from file [c:\inetpub\wwwroot\BISWeb\Dao.xml]
2007-12-07 10:09:24,226 [7752] DEBUG Spring.Objects.Factory.Support.AbstractObjectDefin itionReader [(null)] - Using the following XmlReader implementation : System.Xml.XmlValidatingReader
2007-12-07 10:09:24,289 [7752] DEBUG Spring.Objects.Factory.Xml.DefaultObjectDefinition DocumentReader [(null)] - Loading object definitions.
2007-12-07 10:09:24,289 [7752] DEBUG Spring.Objects.Factory.Xml.ObjectDefinitionParserH elper [(null)] - Loading object definitions...
2007-12-07 10:09:24,289 [7752] DEBUG Spring.Objects.Factory.Xml.ObjectDefinitionParserH elper [(null)] - Default lazy init 'false'.
2007-12-07 10:09:24,289 [7752] DEBUG Spring.Objects.Factory.Xml.ObjectDefinitionParserH elper [(null)] - Default dependency check 'none'.
2007-12-07 10:09:24,289 [7752] DEBUG Spring.Objects.Factory.Xml.ObjectDefinitionParserH elper [(null)] - Default autowire 'no'.
2007-12-07 10:09:24,320 [7752] DEBUG Spring.Objects.Factory.Xml.ObjectsNamespaceParser [(null)] - Registering object definition with id 'DbProvider'.
2007-12-07 10:09:24,351 [7752] DEBUG Spring.Objects.Factory.Xml.ObjectsNamespaceParser [(null)] - Registering object definition with id 'MySessionFactory'.
2007-12-07 10:09:24,351 [7752] DEBUG Spring.Objects.Factory.Xml.ObjectsNamespaceParser [(null)] - Registering object definition with id 'hibernateTransactionManager'.
2007-12-07 10:09:24,351 [7752] DEBUG Spring.Objects.Factory.Xml.ObjectsNamespaceParser [(null)] - Registering object definition with id 'HibernateTemplate'.
2007-12-07 10:09:24,351 [7752] DEBUG Spring.Objects.Factory.Xml.ObjectsNamespaceParser [(null)] - Registering object definition with id 'GenericDao'.
2007-12-07 10:09:24,351 [7752] DEBUG Spring.Objects.Factory.Xml.ObjectsNamespaceParser [(null)] - Registering object definition with id 'UserControllerDao'.
2007-12-07 10:09:24,351 [7752] DEBUG Spring.Objects.Factory.Xml.ObjectsNamespaceParser [(null)] - Registering object definition with id 'BisUser'.
2007-12-07 10:09:24,351 [7752] DEBUG Spring.Objects.Factory.Xml.ObjectsNamespaceParser [(null)] - Attempting to import object definitions from 'DeclarativeServicesAttributeDriven.xml'.
2007-12-07 10:09:24,351 [7752] DEBUG Spring.Objects.Factory.Support.AbstractObjectDefin itionReader [(null)] - Loading XML object definitions from file [c:\inetpub\wwwroot\BISWeb\DeclarativeServicesAttri buteDriven.xml]
2007-12-07 10:09:24,351 [7752] DEBUG Spring.Objects.Factory.Support.AbstractObjectDefin itionReader [(null)] - Using the following XmlReader implementation : System.Xml.XmlValidatingReader
2007-12-07 10:09:24,351 [7752] DEBUG Spring.Objects.Factory.Xml.DefaultObjectDefinition DocumentReader [(null)] - Loading object definitions.
2007-12-07 10:09:24,367 [7752] DEBUG Spring.Objects.Factory.Xml.ObjectDefinitionParserH elper [(null)] - Loading object definitions...
2007-12-07 10:09:24,367 [7752] DEBUG Spring.Objects.Factory.Xml.ObjectDefinitionParserH elper [(null)] - Default lazy init 'false'.
2007-12-07 10:09:24,367 [7752] DEBUG Spring.Objects.Factory.Xml.ObjectDefinitionParserH elper [(null)] - Default dependency check 'none'.
2007-12-07 10:09:24,367 [7752] DEBUG Spring.Objects.Factory.Xml.ObjectDefinitionParserH elper [(null)] - Default autowire 'no'.
2007-12-07 10:09:24,367 [7752] DEBUG Spring.Objects.Factory.Xml.ObjectsNamespaceParser [(null)] - Registering object definition with id 'autoProxyCreator'.
2007-12-07 10:09:24,367 [7752] DEBUG Spring.Objects.Factory.Xml.ObjectsNamespaceParser [(null)] - Registering object definition with id 'transactionAdvisor'.
2007-12-07 10:09:24,367 [7752] DEBUG Spring.Objects.Factory.Xml.ObjectsNamespaceParser [(null)] - Registering object definition with id 'transactionInterceptor'.
2007-12-07 10:09:24,367 [7752] DEBUG Spring.Objects.Factory.Xml.ObjectsNamespaceParser [(null)] - Registering object definition with id 'attributeTransactionAttributeSource'.
2007-12-07 10:09:24,367 [7752] DEBUG Spring.Objects.Factory.Xml.DefaultObjectDefinition DocumentReader [(null)] - Found 11 <object> elements defining objects.
2007-12-07 10:09:24,367 [7752] DEBUG Spring.Objects.Factory.Xml.DefaultObjectDefinition DocumentReader [(null)] - Found 11 <object> elements defining objects.
2007-12-07 10:09:24,367 [7752] DEBUG Spring.Objects.Factory.Support.AbstractObjectDefin itionReader [(null)] - Loaded 11 bean definitions from location [~/Dao.xml]
2007-12-07 10:09:24,367 [7752] DEBUG Spring.Objects.Factory.Support.AbstractObjectDefin itionReader [(null)] - Loading XML object definitions from file [c:\inetpub\wwwroot\BISWeb\Web.xml]
2007-12-07 10:09:24,367 [7752] DEBUG Spring.Objects.Factory.Support.AbstractObjectDefin itionReader [(null)] - Using the following XmlReader implementation : System.Xml.XmlValidatingReader


Here is the error generated when i tried to use the method SaveOrUpdate



2007-12-07 10:23:02,216 [7252] DEBUG Spring.Data.NHibernate.HibernateTemplate [(null)] - Found thread-bound Session for HibernateTemplate
2007-12-07 10:23:02,247 [7252] DEBUG Spring.Data.NHibernate.HibernateTemplate [(null)] - Not closing pre-bound Hibernate Session after HibernateTemplate
2007-12-07 10:23:02,247 [7252] DEBUG BISWeb.web.EntryRequisition [(null)] - Write operations are not allowed in read-only mode (FlushMode.NEVER) - turn your Session into FlushMode.AUTO or remove 'readOnly' marker from transaction definition
Spring.Dao.InvalidDataAccessApiUsageException: Write operations are not allowed in read-only mode (FlushMode.NEVER) - turn your Session into FlushMode.AUTO or remove 'readOnly' marker from transaction definition
at Spring.Data.NHibernate.HibernateTemplate.CheckWrit eOperationAllowed(ISession session) in l:\projects\Spring.Net\src\Spring\Spring.Data.NHib ernate\Data\NHibernate\HibernateTemplate.cs:line 1279
at Spring.Data.NHibernate.SaveOrUpdateObjectHibernate Callback.DoInHibernate(ISession session) in l:\projects\Spring.Net\src\Spring\Spring.Data.NHib ernate\Data\NHibernate\HibernateTemplate.cs:line 2099
at Spring.Data.NHibernate.HibernateTemplate.Execute(I HibernateCallback action, Boolean exposeNativeSession) in l:\projects\Spring.Net\src\Spring\Spring.Data.NHib ernate\Data\NHibernate\HibernateTemplate.cs:line 903
at Spring.Data.NHibernate.HibernateTemplate.SaveOrUpd ate(Object entity) in l:\projects\Spring.Net\src\Spring\Spring.Data.NHib ernate\Data\NHibernate\HibernateTemplate.cs:line 628
at RheemAdmin.Spring.GenericDao.SaveOrUpdate(Object obj) in c:\documents and settings\efren.casillas\my documents\visual studio projects\rheemadmin\spring\genericdao.cs:line 24
at BISWeb.web.EntryRequisition.btnSalvar_Click(Object sender, EventArgs e) in c:\inetpub\wwwroot\bisweb\web\entryrequisition.asp x.cs:line 187

Erich Eichinger
12-07-2007, 05:21 PM
Hi,

Spring.AOP uses dynamically generated proxies to apply aspects. This means that you need to either use interfaces that can be implemented by such a proxy or your methods need to be virtual if they shall be intercepted. Otherwise there is no way for a proxy to hook into calling your methods.
The recommended way is to use interfaces. Then an intercepted call goes

Client -> Interface Proxy (do some magic here) -> Your Real Object

hope this helps,
Erich

efren.casillas
12-07-2007, 05:27 PM
Do you have an example for this? I have been followed the Northwind Hibernate example, in fact the DeclarativeServicesAttributeDrivern I copied from there in order to be able to use the transaction in my methods

Erich Eichinger
12-07-2007, 05:52 PM
If you look at the Northwind sample, you'll notice the [Transaction] attribute around the FulfillmentService.ProcessCustomer() method. This method is a member of the interface "IFulFillmentService".
In this case, the proxy will dynamically implement the IFulFillmentService interface and wrap calls to ProcessCustomer() within a transaction before delegating them to the real object.

Does this clarify how it works?

In your case this means, that your SaveOrUpdate() method should be virtual or be part of some interface e.g. IGenericDao

-Erich

efren.casillas
12-07-2007, 06:17 PM
OK, SaveOrUpdate method is implemented from a Interface called IGenericDao and the method is marked with [Transaction] and appears this error when i run the application.



PropertyAccessExceptionsException (1 errors); nested PropertyAccessExceptions are: [Spring.Core.TypeMismatchException: Cannot convert property value of type [CompositionAopProxy_181da72547fa494bbcf7971cc7a2a9 32] to required type [RheemAdmin.Spring.GenericDao] for property 'GenericDao'., Inner Exception: Spring.Core.TypeMismatchException: Cannot convert property value of type [CompositionAopProxy_181da72547fa494bbcf7971cc7a2a9 32] to required type [RheemAdmin.Spring.GenericDao] for property 'GenericDao'. at Spring.Core.TypeConversion.TypeConversionUtils.Con vertValueIfNecessary(Type requiredType, Object newValue, String propertyName) in l:\projects\Spring.Net\src\Spring\Spring.Core\Core \TypeConversion\TypeConversionUtils.cs:line 132]


and when i delete that mark ([Transaction]), its run successful but when i tried to saveorupdate appears the previous error that i already told








Spring.Dao.InvalidDataAccessApiUsageException: Write operations are not allowed in read-only mode (FlushMode.NEVER) - turn your Session into FlushMode.AUTO or remove 'readOnly' marker from transaction definition
at Spring.Data.NHibernate.HibernateTemplate.CheckWrit eOperationAllowed(ISession session) in l:\projects\Spring.Net\src\Spring\Spring.Data.NHib ernate\Data\NHibernate\HibernateTemplate.cs:line 1279
at Spring.Data.NHibernate.SaveOrUpdateObjectHibernate Callback.DoInHibernate(ISession session) in l:\projects\Spring.Net\src\Spring\Spring.Data.NHib ernate\Data\NHibernate\HibernateTemplate.cs:line 2099
at Spring.Data.NHibernate.HibernateTemplate.Execute(I HibernateCallback action, Boolean exposeNativeSession) in l:\projects\Spring.Net\src\Spring\Spring.Data.NHib ernate\Data\NHibernate\HibernateTemplate.cs:line 903
at Spring.Data.NHibernate.HibernateTemplate.SaveOrUpd ate(Object entity) in l:\projects\Spring.Net\src\Spring\Spring.Data.NHib ernate\Data\NHibernate\HibernateTemplate.cs:line 628
at RheemAdmin.Spring.GenericDao.SaveOrUpdate(Object obj) in c:\documents and settings\efren.casillas\my documents\visual studio projects\rheemadmin\spring\genericdao.cs:line 24
at BISWeb.web.EntryRequisition.btnSalvar_Click(Object sender, EventArgs e) in c:\inetpub\wwwroot\bisweb\web\entryrequisition.asp x.cs:line 187




I also noticed that I removed the OpenViewSession and everything works.

I implemented the OpenViewSession due I need to use collections in my pojos


Why does this happens?

I already did every requirement to make the transaction works and nothing seems to work, I know that I miss a step.


thank you for ur help

Erich Eichinger
12-07-2007, 06:22 PM
Hi,

you were quite close - since you are dealing with a proxy now, of course you can't use the type GenericDao but instead must use the interface IGenericDao. the message


...
Cannot convert property value of type [CompositionAopProxy_181da72547fa494bbcf7971cc7a2a9 32] to required type [RheemAdmin.Spring.GenericDao] for property 'GenericDao'
...

tells you exactly this. The proxy cannot be cast to GenericDao - only to IGenericDao. This means you should convert your property with the name "GenericDao" from type GenericDao to IGenericDao.

-Erich

efren.casillas
12-07-2007, 06:32 PM
Hi Erich,
you were right, thank you for your help, you're the best.

Do you have exactly in where documentation chapter is explain it all of proxy matters?

Thank you for your help and time

Erich Eichinger
12-07-2007, 06:55 PM
Hi,

You are welcome. Glad I could help. You can find more info in the Spring.NET Reference Documentation (http://www.springframework.net/doc-latest/reference/html/aop.html#aop-proxy-mechanism) about AOP.

-Erich

Tristan
12-16-2007, 05:57 PM
Hi Erich,

your answer si quite clear, and it seems to have worked for Efren's problem, but could you explain why you recommend here to do something like :



<object id="genericDaoTransProxy"
type="Spring.Transaction.Interceptor.TransactionProxyFac toryObject, Spring.Data">

<property name="PlatformTransactionManager" ref="hibernateTransactionManager"/>
<property name="Target">
<object type="RheemAdmin.Spring.IGenericDao, RheemAdmin">
<property name="SessionFactory" ref="MySessionFactory"/>
</object>
</property>


though the Northwind example suggests this :


<object id="TxProxyConfigurationTemplate" abstract="true"
type="Spring.Transaction.Interceptor.TransactionProxyFac toryObject, Spring.Data">

<property name="PlatformTransactionManager" ref="HibernateTransactionManager"/>

<property name="TransactionAttributes">
<name-values>
<add key="Process*" value="PROPAGATION_REQUIRED"/>
</name-values>
</property>
<property name="PreInterceptors" ref="CommonLoggingAroundAdvice"/>
</object>

<object id="FulfillmentServiceUsingTxPFO" parent="TxProxyConfigurationTemplate">

<property name="Target" ref="FulfillmentService"/>

</object>


where FullfillmentService is not an interface :



<object id="FulfillmentService" type="Spring.Northwind.Service.FulfillmentService, Spring.Northwind.Service">
<property name="CustomerDao" ref="CustomerDao"/>
<property name="OrderDao" ref="OrderDao"/>
<property name="ShippingService" ref="ShippingService"/>
</object>


Sorry if I missed something obvious...

thanks,
Tristan.

Tristan
12-16-2007, 06:32 PM
Mmmm... I may have got it... The config file is ok, but Efren has declared :


private GenericDao genericDao;

instead of :


private IGenericDao genericDao;

in his calling service...

Is this what happened ?

Tristan

Erich Eichinger
12-16-2007, 06:45 PM
Hi,

yes - that was exactly the point.

-Erich