嗨,我強迫Envers問題。每類擴展包含@GeneratedAuto的ID等。有兩個實體BaseEntity:休眠Envers找到OneToMany JoinTable
@Audited
@Entity
public class HandballInjury extends Injury {
@OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
@JoinTable(name = "HandballDictionaryFact")
private List<HandballDictionaryFact> handballDictionaryFacts = new ArrayList<HandballDictionaryFact>();
private HandballTimeOfInjury timeOfInjury;
...
}
而且
@Audited
@Entity
@Table(name = "handballDictionaryFact")
public class HandballDictionaryFact extends DictionaryFact{
...
}
*父母雙方都有@Audited註解。我的問題是,當我在HandballInjury上使用AuditEntity查找方法時,它會返回所有屬於傷害但不關心revisionId的字典數據的正確傷害。在數據庫中,一切都保存正確。我認爲,如果表加入,那麼envers看起來只是如果id是正確的,而不看版本。休眠Envers版本:5.1.0.Final
編輯1:
我發現我不是SessionFactory.openSession打開新的會話()。正因爲如此,envers正在進入1個LevelCache來獲取數據。我修好了,但沒有幫助。多數民衆贊成在如何發起查詢:
result = getReader().find(HandballInjury.class, ((HandballInjury) object).getId(), revisionNumber);
也許我應該寫自己的查詢?
我注意到下面的查詢還返回了HandballDictionaryFacts_aud中的所有實體,而不是指定的revisionNumber。
List<HandballDictionaryFact> dictionaryFact = getReader().createQuery()
.forEntitiesAtRevision(HandballDictionaryFact.class, revisionNumber).getResultList();
編輯2: 我發現找到查詢與RevNumber尋找handballDictionaryFact小於或等於handballInjury.RevNumber。我現在的問題是,我可以迫使envers只看起來平等嗎?部分查詢:
and handballdi1_.REV=(
select
max(handballdi2_.REV)
from
dictionaryfact_AUD handballdi2_
where
handballdi2_.DTYPE='HandballDictionaryFact'
and handballdi2_.REV<=?
and handballdi1_.id=handballdi2_.id
)
來自第一次編輯的查詢還檢查revNumber是否小於或等於。
Envers應當施加特別創建的事實中的單個條目'REV'謂詞,以便聚合根的任何關聯(在本例中爲「HandballInjury」)將等於或小於聚合根的關聯。如果您確信它沒有這樣做,請打開一個JIRA票據,並用一個簡單的測試案例來報告問題,以重現錯誤。 – Naros
調試後我發現envers從firstlevelcache而不是數據庫獲取數據。但不知道如何改變這一點。 – MrNetroful
你是說它從Session的1LC或Envers的內部1LC中獲取數據,因爲它們是兩回事。你可以用查詢更新你的文章,以及你如何觀察這種行爲? – Naros