oracle cache mess with mybatis query results(获取不到最新的)
oracle cache mess with mybatis query results (can't get the latest)
我的环境是:
Spring引导+Mybatis+Oracle 10g+Jdk1.8
我在 oracle 中得到了一本名为 table 的书,如下所示:
+---------+------+--------+
| book_id | name | number |
+---------+------+--------+
| 1 | b1 | 123 |
| 2 | b2 | 123 |
| 3 | b3 | 2343 |
+---------+------+--------+
3 rows in set (0.00 sec)
我让它工作并用我写的映射器成功显示它。但是在我用 plsql 向这个 table 插入 2 条记录后,我仍然得到相同的 3 条记录而不是所有 5 条记录(因为下面)当我用 mybatis 映射器查询它时。
+---------+------+--------+
| book_id | name | number |
+---------+------+--------+
| 1 | b1 | 123 |
| 2 | b2 | 123 |
| 3 | b3 | 2343 |
| 4 | b4 | 22343 |
| 5 | b5 | 43 |
+---------+------+--------+
5 rows in set (0.00 sec)
然后我像这样修改了oracle中的缓存策略。
alter table book nocache
又成功了!用mybatis显示5条记录都成功了mapper.But为什么?每次都要清除oracle缓存吗?感觉right.Is没有更好的解决办法?
任何答案都会有所帮助。
谢谢
application.properties
# Spring
spring.resources.static-locations=classpath:/static/
# MyBatis
mybatis.configuration.map-underscore-to-camel-case=true
mybatis.configuration.local-cache-scope=statement
# DataSource 1
spring.datasource.db1.url=jdbc:oracle:thin:@*******
spring.datasource.db1.username=***
spring.datasource.db1.password=***
spring.datasource.db1.driver-class-bookName=oracle.jdbc.OracleDriver
映射器
@Mapper
@Qualifier("bookMapper")
public interface BookMapper {
@Select({"select * from book"})
@Options(useCache = false)
@Results({
@Result(property = "bookId",column = "book_id"),
@Result(property = "bookName",column = "book_name"),
@Result(property = "bookNumber",column = "book_number")
})
List<BookEntity> getALL();
// insertBook();
}
实体
public class BookEntity {
long bookId;
String bookName;
int bookNumber;
//getters and setters
}
问题与缓存清除无关。
我认为除了在 insert( a DML )
语句之后发出 commit
之外没有问题。
如果您没有发出 commit
,您只能从另一个会话中获得 3 条记录。
但是在你发布之后,
alter table book nocache ( a DDL )
,发生隐式提交,您可以看到所有 5 条记录。
我的环境是:
Spring引导+Mybatis+Oracle 10g+Jdk1.8
我在 oracle 中得到了一本名为 table 的书,如下所示:
+---------+------+--------+
| book_id | name | number |
+---------+------+--------+
| 1 | b1 | 123 |
| 2 | b2 | 123 |
| 3 | b3 | 2343 |
+---------+------+--------+
3 rows in set (0.00 sec)
我让它工作并用我写的映射器成功显示它。但是在我用 plsql 向这个 table 插入 2 条记录后,我仍然得到相同的 3 条记录而不是所有 5 条记录(因为下面)当我用 mybatis 映射器查询它时。
+---------+------+--------+
| book_id | name | number |
+---------+------+--------+
| 1 | b1 | 123 |
| 2 | b2 | 123 |
| 3 | b3 | 2343 |
| 4 | b4 | 22343 |
| 5 | b5 | 43 |
+---------+------+--------+
5 rows in set (0.00 sec)
然后我像这样修改了oracle中的缓存策略。
alter table book nocache
又成功了!用mybatis显示5条记录都成功了mapper.But为什么?每次都要清除oracle缓存吗?感觉right.Is没有更好的解决办法? 任何答案都会有所帮助。 谢谢
application.properties
# Spring
spring.resources.static-locations=classpath:/static/
# MyBatis
mybatis.configuration.map-underscore-to-camel-case=true
mybatis.configuration.local-cache-scope=statement
# DataSource 1
spring.datasource.db1.url=jdbc:oracle:thin:@*******
spring.datasource.db1.username=***
spring.datasource.db1.password=***
spring.datasource.db1.driver-class-bookName=oracle.jdbc.OracleDriver
映射器
@Mapper
@Qualifier("bookMapper")
public interface BookMapper {
@Select({"select * from book"})
@Options(useCache = false)
@Results({
@Result(property = "bookId",column = "book_id"),
@Result(property = "bookName",column = "book_name"),
@Result(property = "bookNumber",column = "book_number")
})
List<BookEntity> getALL();
// insertBook();
}
实体
public class BookEntity {
long bookId;
String bookName;
int bookNumber;
//getters and setters
}
问题与缓存清除无关。
我认为除了在 insert( a DML )
语句之后发出 commit
之外没有问题。
如果您没有发出 commit
,您只能从另一个会话中获得 3 条记录。
但是在你发布之后,
alter table book nocache
( a DDL )
,发生隐式提交,您可以看到所有 5 条记录。