2012-12-10 35 views
0

使用Glassfish 3.1.2和eclipselink 2.2.0。 我必須跟蹤以下實體的變化:對OneToOne屬性的審計

@Entity 
@EntityListeners({AuditListener.class}) 
@Customizer(AuditListener.class) 
public class Client extends Person { 
... 
@OneToOne(cascade = {CascadeType.PERSIST, CascadeType.MERGE}) 
private ConsumptionRoomAndPost consumptionRoomAndPost; 
... 
@OneToMany(cascade = {CascadeType.PERSIST, CascadeType.MERGE}) 
private List<Document> documentList; 
... 

AuditListener:

public class AuditListener extends DescriptorEventAdapter implements DescriptorCustomizer { 
... 
@Override 
public void postMerge(DescriptorEvent event) { 
    if (event.getChangeSet() != null) { 
    ... 
    } 
} 

}

這適用於文檔列表,變更爲不爲空, 而不是ConsumptionRoomAndPost 。 changeSet是空的。

當然,我可以爲ConsumptionRoomAndPost添加自己的偵聽器ConsumptionRoomAndPostAuditListener,但對於審計,我需要客戶端信息,並且我有問題可以將此客戶端信息提供給ConsumptionRoomAndPostAuditListener。

回答

0

已解決。

將關係更改爲雙向後,eclipse鏈接跟蹤所有屬性的更改。 我已經加入到實體ConsumptionRoomAndPost:

public class ConsumptionRoomAndPost { 
... 
@OneToOne(mappedBy = "consumptionRoomAndPost", cascade = CascadeType.ALL) 
private Client client; 
... 
} 

其所有。