[英]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.