Spring ReadOnly Transaction with Propagation.SUPPORTS with WebSphere and Oracle

随声附和 提交于 2019-12-23 01:37:41

问题


I have some problems with Transaction/Session management, since I switched from Hibernate 3.6 to Hibernate 4.1.x

I use Spring 3.1.2, Hibernate 4.1.4, WebSphere 8.5 and Oracle 11.

In my WebApp I have marked some methods with:

@Transactional(propagation = Propagation.SUPPORTS, readOnly = true)

Thats working fine for my webapp which uses OpenSessionInViewFilter and getSessionFactory().getCurrentSession().

But some of my code is called by JMS or Quartz job (without the OpenSessionInViewFilter) resulting in

org.hibernate.HibernateException: No Session found for current thread
    at org.springframework.orm.hibernate4.SpringSessionContext.currentSession(SpringSessionContext.java:97)

After some researches in the Internet I changed my Transaction to :

@Transactional(propagation = Propagation.REQUIRED, readOnly = true)

Now there is an open Session and everything is OK for Tomcat but on WebSphere I get the following error:

[SqlExceptionHelper] : SQL Error: 0, SQLState: null
[SqlExceptionHelper] : DSRA9010E: 'setReadOnly' wird in der WebSphere-Implementierung  java.sql.Connection nicht unterstützt.

Some posts say, Oracle isn´t supporting readonly. But with Propagation.SUPPORTS or with Tomcat it´s working. Now I don´t know what to do. Marking all methods called by JMS with Propagation.REQUIRED and readOnly = false?

Any better ideas? Or is this a bug in Spring when using WebSphere?


回答1:


Translating the error in english it says:

DSRA9010E: 'setReadOnly' is not supported in the WebSphere implementation java.sql.Connection

Which is not a bug, it's simply that they are not implementing read-only. And that is also understandable if using a Connection Pooling because readonly is usually a connection creation scoped attribute.

Moreover readonly is only a "suggestion" for the jdbc provider: the jdbc provider can ignore it and as far as I know many providers don't really do anything for it.

Simply don't specify readonly.


To answer Sam comment below: Hibernate has nothing to do with that error, it is the Websphere Component implementing java.sql.Connection that emits DSRA9010E error when using Websphere with Oracle, after June 2003, as explained here by IBM itself about specifically that error code DSRA9010E and description "'setReadOnly' is not supported on the IBM WebSphere Application Server java.sql.Connection implementation":

Resolving the problem

In June 2003, there was a change made to the Application Server code defect 168102. Prior to June 2003, the setReadOnly(true) method set an internal flag in Application Server, but did not convey this information to the Oracle database. In versions after June 2003, Application Server issues the error as described above.

My understanding of the entire article is that they added that error later, to resolve the problem, as a solution to defect 168102, for clarity purpose: to let the client know that setting that flag has no effect on the underlying database connection because Oracle is not supporting it.

At the end of the article they suggest to upgrade to the latest version (the one that emits the error).




回答2:


Yes Oracle does not support read-only and this hint will be ignored, maybe you will lost bit more performance. You can remove those flags, instead you can make it entity level @Immutable (this annotation needs little bit attention) or you can update entity fields @column(updatable = false, insertable = false).



来源:https://stackoverflow.com/questions/13310808/spring-readonly-transaction-with-propagation-supports-with-websphere-and-oracle

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!