我的环境是:
Spring Boot + Mybatis + Oracle 10g +10g 1.8
我在甲骨文里有一张书是这样的:
+---------+------+--------+
| book_id | name | number |
+---------+------+--------+
| 1 | b1 | 123 |
| 2 | b2 | 123 |
| 3 | b3 | 2343 |
+---------+------+--------+
3 rows in set (0.00 sec)当我用plsql将2条记录插入到这个表中之后,我成功地用我编写的.But映射器显示了它,在使用mapper查询它时,我仍然得到了相同的3条记录,而不是所有5条记录(如下所示)。
+---------+------+--------+
| 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它又起作用了!所有5张记录都是用mapper.But成功显示的,为什么?我应该每次清除甲骨文缓存吗?这不觉得right.Is有更好的解决方案吗?任何答案都会有帮助。thx
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
}发布于 2017-10-31 13:09:18
此问题与缓存清除无关。
我认为除了在您的commit语句之后发布一个insert( a DML )之外,没有任何问题。
如果没有发出commit,则只能从另一个会话中获得3条记录。
但在你发布后,
修改表书nocache
( a DDL )
,就会发生隐式提交,您可以看到所有5条记录。
https://stackoverflow.com/questions/47034820
复制相似问题