我嘗試用Java和Hibernate實現文檔修改跟蹤系統。文檔的每個模塊都保存有autor和時間戳。要獲得文檔的創建者,我需要獲得最早的mod。那就是:由查詢定義的Hibernate實體屬性
@Entity
@Table(name="Modifications")
public class Modification
{
String autor;
Date dateTime;
Document document;
@ManyToOne
public Document getDocument() {
...
}
// Author of this mod
@Column(name="Autor")
public String getAutor() {
...
}
// and other properties
}
@Entity
@Table(name="Documents")
public class Document
{
private List<Modification> modifications;
@OneToMany(mappedBy="document")
public List<Modification> getModifications() {
...
}
// this property is question about. How should I implement this with hibernate?
//I don't want to store "autor" field in entity,
//it should be determined with query to modifications table.
// But I can't find any example of defining properties this way...
// So I need your advices :)
public String getAutor() {
...
}
// other properties
}