Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
576 views
in Technique[技术] by (71.8m points)

jpa - envers multi level entity revision howto

User have n Contacts. A Contact can have a localized Comment (Comments are shared between Contacts). Java Beans:

@Audited
@Entity
public class User {
    @OneToMany(fetch = FetchType.EAGER,
               cascade = CascadeType.ALL,
               orphanRemoval = true)
    Set<Context> contacts;
}

@Audited
@Entity
public class Contact {
    @ManyToOne(fetch = FetchType.EAGER,
               cascade = {
                          CascadeType.MERGE,
                          CascadeType.PERSIST,
                          CascadeType.REFRESH})
    Comment comment;
}

@Audited
@Entity
public class Comment {
    String de;
    String en;
    String fr;
}

If I change the german localization (Comment.de) of a contact (Contact.comment) then this will create a new revision but not for User. If I ask envers for User Revisions I will never see this "Level 2 change" because the relation between User and Contact was not change, only the german string in the Contact Comment was changed.

But I want see in the User History a new Entry (Changed german comment for contact XYZ).

How can I do this? :D

Thxs

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Maybe an idea would be to use a custom revision log (http://docs.jboss.org/hibernate/orm/4.1/devguide/en-US/html/ch15.html#envers-revisionlog) in which you store the "root" entity/entities for which the change is relevant. This may not be the most efficient but depending on your domain model, this may be what you want.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

56.8k users

...