在Spring中设置的read-only='true' 不起作用,仍可以执行写操作;但是其他的正常,如遇到异常则事务能成功回滚等。据说是DataSourceTransactionManager不支持的原因,ibatis只能用打DataSourceTransactionManager吗?
这个问题挺郁闷,难道不能设置只读查询吗,这样会影响效率吧。
哪位知道此问题的解决办法
这个问题挺郁闷,难道不能设置只读查询吗,这样会影响效率吧。
哪位知道此问题的解决办法
解决方案 »
- 一个页面的逻辑问题。不要代码,只要思路.希望高手来讨论一下。
- JAVA做一个目录树,要求实现节点间能够拖拉移动,用什么技术好?
- login.do的问题
- 怎樣在jsp頁面中單擊一個鏈接或按鈕如"匯出Excle"將數據庫中查處數據以.xls的文檔存到本機????
- 很急又很简单的问题,,
- 求助 按纽按下一次后, 如何变为无效.
- 各位大师,小弟跪求SSH整合项目实战视频, 如有 麻烦告诉一下
- 启动socketxp后,怎么我的tomcat启动不起来,将socketxp关掉就可以了,为什么
- 请问jsp大虾:在*.jsp文件中可以有自己独立编写的类吗?
- maven插件安装
- ssh一连接数据库就报空指针
- jsp多选项卡浏览问题
例如:PROPAGATION_REQUIRED,REPEATABLE READ,readOnly,-MyCheckedException,3 readOnly表示对应的事务应该被最优化为只读事务,例如在使用Hibernate时避免dirty checking
主要目的是 不要加写锁,提高读和其他线程写的速度。
void org.springframework.jdbc.datasource.DataSourceTransactionManager.doBegin(Object transaction, TransactionDefinition definition)
里的代码
Integer previousIsolationLevel = DataSourceUtils.prepareConnectionForTransaction(con, definition);
txObject.setPreviousIsolationLevel(previousIsolationLevel); // Switch to manual commit if necessary. This is very expensive in some JDBC drivers,
// so we don't want to do it unnecessarily (for example if we've explicitly
// configured the connection pool to set it already).
if (con.getAutoCommit()) {
txObject.setMustRestoreAutoCommit(true);
if (logger.isDebugEnabled()) {
logger.debug("Switching JDBC Connection [" + con + "] to manual commit");
}
con.setAutoCommit(false);
}
需要换下位置
if (con.getAutoCommit()) {
txObject.setMustRestoreAutoCommit(true);
if (logger.isDebugEnabled()) {
logger.debug("Switching JDBC Connection [" + con + "] to manual commit");
}
con.setAutoCommit(false);
}
Integer previousIsolationLevel = DataSourceUtils.prepareConnectionForTransaction(con, definition);
txObject.setPreviousIsolationLevel(previousIsolationLevel);可能是ORACLE JDBC对这个顺序要限制,继续测试中
Class.forName("oracle.jdbc.OracleDriver");
Connection con=DriverManager.getConnection("jdbc:oracle:thin:@xxxxx","test","test");
con.setAutoCommit(false);
con.setReadOnly(true);
//con.setAutoCommit(false);
PreparedStatement pst2 = con.prepareStatement("select * from order_tb");
ResultSet rs = pst2.executeQuery();
while (rs.next())
{
System.err.println(rs.getString(1) + "<<<<<>>>>>" + rs.getString(2)); }
rs.close();
pst2.close();
String sqlStr="insert into order_tb (id,name) values (?,?)";
sqlStr="update order_tb set id=?,name=?";
PreparedStatement pst = con.prepareStatement(sqlStr);
pst.setInt(1, 1);
pst.setString(2, "ccccccc");
pst.execute();
pst.close();
con.commit();