Announcement Announcement Module
Collapse
No announcement yet.
Creating History Object - Some ideas wanted Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Creating History Object - Some ideas wanted

    Hi,

    I am using Jboss3.2.4 for my App Server, Hibernate 2.1.8 for ORM and Spring 1.2 RC1.

    I want to create a History what i mean is if I have

    Code:
    class User{
    
    protected Long id;
    protected String firstName;
    protected String lastName;
    protected String empId;
    
    protected Set roles = new HashSet;
    
    }
    Stored in a table T_USER, I need a corresponding T_USER_HIST which has the same attributes as the original object. For every update to the user object a corresponding row has to be created in the history table(previous state of user).

    Also User has a m-n relationship with Role and he may be assigned new Roles. I should be able to capture the assignment of Roles as well. Also there could 1-n relations or self relation(parent/child relationships). Any modification to the children should be captured in the corresponding history table.

    I cannot use stored procedures. I also looked at hibernate site http://www.hibernate.org/195.html for some ideas.

    Any suggestions are welcome.

    Thanks

  • #2
    If you can change to Hibernate3 then you could easily use its event listener architecture to capture User update.

    Example:

    config.setListener("delete", new BasicDeleteEventListener());

    public class BasicDeleteEventListener extends DefaultDeleteEventListener {

    public void onDelete(DeleteEvent event) throws HibernateException {
    if (Service.class.isAssignableFrom(Hibernate.getClass (event.getObject()))) {
    deleteWebClientFlow(event.getSession(), (Service)event.getObject());
    }
    super.onDelete(event);
    }

    Comment

    Working...
    X