[英]Quarkus Panache Hibernate: How to clear the cache, make entity world match the database state?
我是 quarkus 的新手,似乎在单元测试中遇到了 hibernate 缓存的问题。 该测试注入了“UserTransaction”。 该测试应检查数据库清理任务。
这就是我要做的:
Document doc;
UUID uuid;
doc = new Document();
uuid = UUID.randomUUID();
doc.uuid = uuid;
doc.doc = new byte[0];
doc.createdAt = Instant.now();
transaction.begin();
doc.persistAndFlush();
transaction.commit();
doc = Document.findById(uuid);
Assertions.assertNotNull(doc);
TimeUnit.SECONDS.sleep(Long.parseLong(maxAge)+1);
scheduler.cleanUp();
doc = Document.findById(uuid);
Assertions.assertNull(doc);
第 7 步失败,因为 'find(id)' 返回实体,尽管它不再在数据库中。
如果我跳过第 5 步,这不会发生! 所以这对我来说似乎是缓存问题。
我试图注入 'Session'、'SessionFactory' 和 'EntitiyManager' 以访问当前的 Hibernate 会话,但如果成功则没有。
也许整个方法缺少我没有得到的东西? 如何在像我这样的设置中使实体世界与数据库匹配?
欢迎任何提示和想法。
TIA
问题有一个简单的解决方法,在最后的find操作中添加一个事务:
transaction.begin();
doc = Document.findById(uuid);
transaction.commit();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.