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

  • Creating History Object - Some ideas wanted


    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

    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 for some ideas.

    Any suggestions are welcome.


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


    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());